Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ssokolowskisebastian/5d93b58e65853de066c7575dfed789e6 to your computer and use it in GitHub Desktop.
Save ssokolowskisebastian/5d93b58e65853de066c7575dfed789e6 to your computer and use it in GitHub Desktop.
import time
start_time = time.time()
# b(b-1)/(b+r)(b+r-1)... b= (1+sqrt(8r^2+1))//2 + r
# k^2-8r^2=1 (3,1)
# (xx'+yy'd)+(xy'+x'y)sqrt(d) => 3*x+8*y, x+3*y
def solution(limit):
x, y = 3, 1
while 2*y+(x+1)//2 < limit:
x, y = 3*x+8*y, x+3*y
yield y+(x+1)//2
print([x for x in solution(10**12)][-1])
print("--- %s seconds ---" % (time.time() - start_time))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment