Pell's equation: Difference between revisions
Content added Content deleted
Alextretyak (talk | contribs) (Added 11l) |
Drkameleon (talk | contribs) (Added Arturo implementation) |
||
Line 99: | Line 99: | ||
x^2 - 277 * y^2 = 1 for x = 159150073798980475849 and y = 9562401173878027020 |
x^2 - 277 * y^2 = 1 for x = 159150073798980475849 and y = 9562401173878027020 |
||
</pre> |
</pre> |
||
=={{header|Arturo}}== |
|||
{{trans|Python}} |
|||
<lang rebol>solvePell: function [n][ |
|||
x: to :integer sqrt n |
|||
[y, z, r]: @[x, 1, shl x 1] |
|||
[e1, e2]: [1, 0] |
|||
[f1, f2]: [0, 1] |
|||
while [true][ |
|||
y: (r * z) - y |
|||
z: (n - y * y) / z |
|||
r: (x + y) / z |
|||
[e1, e2]: @[e2, e1 + e2 * r] |
|||
[f1, f2]: @[f2, f1 + f2 * r] |
|||
[a, b]: @[e2 + f2 * x, f2] |
|||
if 1 = (a*a) - n*b*b -> |
|||
return @[a, b] |
|||
] |
|||
] |
|||
loop [61 109 181 277] 'n [ |
|||
[x, y]: solvePell n |
|||
print ["x² -" n "* y² = 1 for (x,y) =" x "," y] |
|||
]</lang> |
|||
{{out}} |
|||
<pre>x² - 61 * y² = 1 for (x,y) = 1766319049 , 226153980 |
|||
x² - 109 * y² = 1 for (x,y) = 158070671986249 , 15140424455100 |
|||
x² - 181 * y² = 1 for (x,y) = 2469645423824185801 , 183567298683461940 |
|||
x² - 277 * y² = 1 for (x,y) = 159150073798980475849 , 9562401173878027020</pre> |
|||
=={{header|C}}== |
=={{header|C}}== |