程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Python Blue Bridge Cup basic-04 Fibonacci series

編輯:Python

  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])


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved