Project Euler 197
题目
Investigating
the behaviour of a recursively defined sequence
Given is the function ( is the
floor-function), the sequence
is defined by and .
Find for .
Give your answer with digits
after the decimal point.
解决方案
将序列打印出多项后发现,到了某一个下标(大约 前后)之后,数列的值是两个数反复交替出现。因此枚举量为常数,直接模拟。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| N = 10 ** 12 M = min(N, 600)
def f(x: float): return int(2 ** (30.403243784 - x * x)) * 1e-9
a = [-1] for i in range(M): a.append(f(a[-1])) ans = a[M] + a[M - 1] print(ans)
|