Problem description
Fibonacci The recurrence formula of sequence is :Fn=Fn-1+Fn-2, among F1=F2=1.
When n The larger the ,Fn It's also very large. , Now we want to know ,Fn Divide 10007 What is the remainder of .
Input format
Input contains an integer n.
Output format
Output one line , Contains an integer , Express Fn Divide 10007 The remainder of .
explain : In the subject , The answer is demand Fn Divide 10007 The remainder of , So we just need to work out the remainder , You don't have to work out Fn The exact value of , Then divide the result of the calculation by 10007 Take the remainder , It is often easier to calculate the remainder directly than to calculate the original number first .
for example : Input
10
For example, output
55
The sample input
22
Sample output
7704
Data scale and agreement
1 <= n <= 1,000,000.
// Run timeout code
def svd(n):
if(n==1 or n==2):
return 1
else:
return svd(n - 1) % 10007 + svd(n - 2) % 10007
n=int(input())
print(svd(n))
a=[]
a.append(1)
a.append(1)
n=int(input())
f=n-1
for i in range(2,n):
a.append((a[i-1]+a[i-2])%10007)
print(a[f])
After writing the interface wi