Introductory training Fibonacci Sequence time limit: 1.0s memory limit: 256.0MBProblem description
fibonacci sequence is: Fn =fn-1 +fn-2 , wherein F1 =f2 = 1.
When n is large, fn is also very large, and now we want to know what the remainder of fn divided by 10007 is.
Input format input contains an integer n. The output format outputs a line that contains an integer representing the FNDivide by the remainder of 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, without first calculating the exact value of fn , and then dividing the calculated result by 10007 to take the remainder, The direct calculation of the remainder is often simpler than calculating the original number and then taking more than 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>using namespace Std;int f[1000001];int main () { int n; F[1]=1;f[2]=1; cin>>n; for (int i=3;i<=1000000;i++) { f[i]=f[i-1]+f[i-2]; f[i]%=10007; } cout<<f[n]; return 0;}
Blue Bridge Cup-introductory training-fibonacci series