Fibonacci数列的递推公式为:Fn=Fn-1+Fn-2,其中F1=F2=1。
当n比较大时,Fn也非常大,现在我们想知道,Fn除以10007的余数是多少。
int a1, a2;
a1 = a2 = 1;
int sum = 0, temp;//sum是保存余数的变量 ,temp是为了方便交换数据
long n;//因为n>=1 and n<=1000000
cin >> n;
for (long i = 1; i <= n; i++)
{
sum = a1 % 10007;
temp = a2;
a2 = (a1 + a2) % 10007;
a1 = temp;
}
cout << sum;
上面的for循环是什么意思?