Anonymous user
Pell's equation: Difference between revisions
→{{header|Python}}: It's far more Pythonic to use multiple assignment than a helper method which uses arrays for pass-by-reference
(Added Wren) |
(→{{header|Python}}: It's far more Pythonic to use multiple assignment than a helper method which uses arrays for pass-by-reference) |
||
Line 876:
<lang python>import math
def
x = int(math.sqrt(n))
y, z, r = x, 1, x << 1
while True:
y = r * z - y
z =
r = (x + y) // z
fun(e1, e2, r)▼
fun(f1, f2, r)▼
a[0] = f2[0]▼
fun(b, a, x)▼
if a[0] * a[0] - n * b[0] * b[0] == 1:▼
for n in [61, 109, 181, 277]:
print("x^2 - %3d * y^2 = 1 for x = %27d and y = %25d" % (n, x
{{out}}
<pre>x^2 - 61 * y^2 = 1 for x = 1766319049 and y = 226153980
|