题解 | #兔子的数量#
兔子的数量
https://www.nowcoder.com/practice/8783056676de4396b0bf816a3561d62f
import sys mon = sys.stdin mon = int(str(mon.read())) out = 0 def count_rabbit(mont): t_out1 = 0 t_out2 = 0 t_out = 0 for _ in range(1, mont + 1): if _ == 1: t_out1 = 1 t_out2 = 1 else: tmp = t_out1 t_out1 = t_out2 t_out2 = tmp + t_out1 t_out = t_out1 + t_out2 return t_out out = count_rabbit(mon) print(out)
解题思路在于梳理两个加数之间的关系,当n=1的时候 可以看成a=1 b=1 c=a+b; n=2的时候,a = 之前的b b =之前a+现在的a,c = 现在的a + 现在的b, 以此类推。
#解题#