Pell's equation: Difference between revisions

added langur language example
m (→‎{{header|zkl}}: Fix link: Perl 6 --> Raku)
(added langur language example)
Line 528:
x^2 - 181 * y^2 = 1 for x = 2,469,645,423,824,185,801 and y = 183,567,298,683,461,940
x^2 - 277 * y^2 = 1 for x = 159,150,073,798,980,475,849 and y = 9,562,401,173,878,027,020</pre>
 
=={{header|langur}}==
{{trans|D}}
<lang langur>val .fun = f [.b, .b x .c + .a]
 
val .solvePell = f(.n) {
val .x = truncate .n ^/ 2
var (.y, .z) = (.x, 1)
var .r = .x x 2
var (.e1, .e2) = (1, 0)
var (.f1, .f2) = (0, 1)
 
for {
.y = .r x .z - .y
.z = (.n - .y x .y) \ .z
.r = (.x + .y) \ .z
(.e1, .e2) = .fun(.e1, .e2, .r)
(.f1, .f2) = .fun(.f1, .f2, .r)
var (.a, .b) = (.f2, .e2)
(.b, .a) = .fun(.b, .a, .x)
if .a x .a - .n x .b x .b == 1: return [.a, .b]
}
}
 
for .n in [61, 109, 181, 277] {
val (.x, .y) = .solvePell(.n)
writeln $".x^2 - \.n:3; x .y^2 = 1 for .x = \.x:27; and .y = \.y:25;"
}</lang>
 
{{out}}
<pre>.x^2 - 61 x .y^2 = 1 for .x = 1766319049 and .y = 226153980
.x^2 - 109 x .y^2 = 1 for .x = 158070671986249 and .y = 15140424455100
.x^2 - 181 x .y^2 = 1 for .x = 2469645423824185801 and .y = 183567298683461940
.x^2 - 277 x .y^2 = 1 for .x = 159150073798980475849 and .y = 9562401173878027020</pre>
 
=={{header|Perl}}==
885

edits