Blue Bridge Cup induction training several columns --Fibonacci

Too long I did not do arithmetic problem, a little novices, a simple question to be stuck. (╯▔ dish ▔) ╯

Problem description
the Fibonacci recursion formula: Fn = Fn-1 + Fn -2, where F1 = F2 = 1.

When n is relatively large, Fn is very great, and now we want to know, Fn is divided by the number 10007 is.

Input format
input contains an integer n.
Output format
output one line containing an integer representing the Fn remainder of the division of 10007.
Description: In this problem, the answer is to require Fn is divided by 10007, so we can figure this out as long as the remainder can be, without the need to calculate the exact value of Fn, then the result is calculated by dividing the number 10007 to take over direct calculation the remainder often than first calculate the original number and then take the remainder simple.

Solution:
This question is to focus on the subject inside tips, do not directly derive the values of Fn go computing the remainder. Initially a little time to see do not understand. Consideration may be because then Fn is greater than the time when the 10007, which is stored in an array value Fn is too large, resulting in operation may slow down, but if the cycle, each F [i-2] + F [i-2 ]% are 10007, then you can increase the speed of operation.

This question is at the same time there must pay attention to is the definition of an int array in the beginning of time to define multi-system test data is relatively large. I define an array of int variables 1 million just over detection.

Guess you like

Origin www.cnblogs.com/Reton/p/12142148.html