Introductory training Fibonacci Sequence time limit: 1.0s memory limit: 256.0MBProblem description
The recursive formula for the Fibonacci sequence is: FN=fn-1+fn-2, of which f1=f2=1.
When n is large, fn is also very large, and now we want to know what theremainder of f n divided by 10007 is.
Input format input contains an integer n. The output format outputs a line that contains an integer representing the F
The remainder of n divided by 10007.Note: In the subject, the answer is to ask Fn divided by 10007 of the remainder, so as long as we can calculate the remainder can be, and do not need to calculate theexact value of f N, and then divide the result of the calculation by 10007 to take the remainder, the direct calculation of the remainder is often more simple than the original number of the first.
Sample input 10 Sample Output 55 Sample input 22 sample output 7704 data scale and Convention 1 <= N <= 1,000,000.#include <iostream>#include<cstdio>using namespacestd;intMain () {intf1,f2,n,f; while(~SCANF ("%d",&N)) {intm=10007; if(n==1|| n==2) {printf ("1\n"); Continue; } N=n-2; F1=f2=1; while(n--) {f= (F1+F2)%m; F1=f2%m; F2=f%m; } printf ("%d\n", f%m); } return 0;}
Blue Bridge Cup-introductory training Fibonacci series