Ich versuche mich seit geraumer Zeit am Problem #66. Ich habe zur Bestimmung des x-Wertes die Gleichung umgeformt:
Code: Alles auswählen
x^2 - D * y^2 = 1
<=> x = sqrt(1 + D * y^2)
Code: Alles auswählen
from math import sqrt
D = 1000
store = 0
for d in xrange(2, D + 1):
# continue if d is square
if sqrt(d)**2 == d:
continue
y = 1
while True:
x = sqrt(1 + d * y**2)
if int(x) == x:
if x > store:
store = x
print "D = %i (x is %i, y is %i)" % (d, x, y)
break
y += 1
Code: Alles auswählen
>>> x = 1592796237
>>> y = 64123562
>>> D = 617
>>> sqrt(1 + D * y**2)
1592796237.0
>>> x == _
True
>>> x**2 - D * y**2
421L
P.S.: Ich suche natürlich nicht die Lösung des eigentlichen Problems, sondern Hilfestellung hinsichtlich meines Ansatzes..