Euler project(Python 0.000543)
wikipedia: 連分数の性質からすぐ求めることができる。
import math from datetime import datetime def Euler65(): P = [1, 2] A = [2, 1] count = 1 for i in xrange(3,101): if i % 3 == 0: A.append(2 * count) count += 1 else: A.append(1) for i in xrange(2,101): p = A[i-1]*P[i-1]+P[i-2] P.append(p) total = map(int, list(str(P[100]))) return sum(total) def main(): start = datetime.now() answer = Euler65() end = datetime.now() print end - start, answer if __name__ == "__main__": main()