Example Analysis of Fibonacci sequence in SpringBoot
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)