Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Fibonacci sequence in SpringBoot

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly shows you the "sample analysis of Fibonacci series in SpringBoot", which is easy to understand and clear. I hope it can help you solve your doubts. Let me lead you to study and study the "sample analysis of Fibonacci series in SpringBoot".

For this problem, get the hand, immediately think of is: first find the Fibonacci sequence, and then find the remainder. But such a violent calculation is highly discouraged. Because when n is very large, the calculation time is long, and numerical overflow may occur!

So, here's another way of thinking: finding the remainder indirectly.

First of all, popular science has a remainder formula: (aquib)% c = (a%c+b%c)% c

This formula is not difficult to understand. You can try it on your behalf.

Therefore, it is not difficult to get: F (n)% m = [f (nmur1) + f (nMur2)]% m = [f (nmur1)% m (nmur2)% m]% m

As can be seen from the title, the final solution is f (n)% m, so that: G (n) = f (n)% m, where m is 10007.

So the recurrence formula of the remainder is: G (n) = [g (nmur1) + g (nMur2)]% m

Among them, mreply 10007 g (1) = g (2) = 1%m=1

The complete code is as follows:

# include using namespace std;int main () {int f1mlrect f2y1int temp=0; / / intermediate variable int output=0; / / output long noun 0; / / initialize input cin > > natives if (natives 1 | | natives 2) {output=1; / / when nasty 1 or 2, output is 1} else {for (int iTunes 3 miti)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report