Blue Bridge Cup C language entry-level training of the fiber-ACCI series, Blue Bridge fiber-ACCI
Problem description
The recurrence formula of the Fibonacci series is: Fn = Fn-1 + Fn-2, where F1 = F2 = 1.
When n is large, Fn is very large. Now we want to know the remainder of Fn divided by 10007.
The input format contains an integer n. The output format outputs a row containing an integer that represents the remainder of Fn divided by 10007.
Note: In this question, the answer is to divide Fn by the remainder of 10007. Therefore, we only need to calculate this remainder without first calculating the exact Fn value, then, divide the calculated result by 10007 to obtain the remainder. It is easier to calculate the remainder directly than to calculate the original number first and then obtain the remainder.
Sample input 10 sample output 55 sample input 22 sample output 7704 data size and Convention 1 <= n <= 1,000,000.
# Include <stdlib. h> # include <stdio. h> # define MOD 10007 # define MAXN 1000001int n, I, F [MAXN]; int main () {scanf ("% d", & n ); F [1] = 1; F [2] = 1; for (I = 3; I <= n; ++ I) F [I] = (F [I-1] + F [I-2]) % MOD; printf ("% d \ n", F [n]); return 0 ;}