You are viewing a single comment's thread. Return to all comments →
Python 3 solution, using the fact that the continued fraction of e has a pattern of 2 1 1 4 1 1 6 11, ..., from index 2:
N = int(input()) from math import e n0, n1 = 1, 2 t = 1 for i in range(1, N): n0, n1 = n1, n0 + t*n1 t = 1 if (i - 1) % 3 != 0 else ((i - 1) // 3 + 1) * 2 print(sum(map(int, str(n1))))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #65: Convergents of e
You are viewing a single comment's thread. Return to all comments →
Python 3 solution, using the fact that the continued fraction of e has a pattern of 2 1 1 4 1 1 6 11, ..., from index 2: