题解 | #斐波那契数列#
斐波那契数列
http://www.nowcoder.com/practice/ee5d403c1172487f8c7915b3c3d924c6
这里使用递归的话,时间复杂度为,超时了,因此我们只能使用for循环,具体如下
def fib(n):
assert n>0
a,b = 0, 1
for i in range(1, n+1):
a,b = b, a+b
return a
n = int(input())
print(fib(n))