牛客华为机试HJ37
作者:互联网
1. 题目描述
2. Solution
1、思路分析
斐波那契数列
2、代码实现
import sys
if sys.platform != "linux":
sys.stdin = open("input/HJ37.txt")
# 迭代实现
def solve(n):
a, b = 0, 1
for i in range(n):
a, b = b, a + b
print(a)
def tail_recur(n, n1, n2):
if n == 1:
return n1
return tail_recur(n - 1, n2, n1 + n2)
for line in sys.stdin:
n = int(line.strip())
# solve(n)
print(tail_recur(n, 1, 1))
标签:recur,sys,牛客,tail,n1,print,机试,n2,HJ37 来源: https://www.cnblogs.com/junstat/p/16168265.html