Pell's equation: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
|||
Line 677: | Line 677: | ||
.e1, .e2 = .fun(.e1, .e2, .r) |
.e1, .e2 = .fun(.e1, .e2, .r) |
||
.f1, .f2 = .fun(.f1, .f2, .r) |
.f1, .f2 = .fun(.f1, .f2, .r) |
||
val .b, .a = .fun(.e2, .f2, .x) |
|||
.b, .a = .fun(.b, .a, .x) |
|||
if .a^2 - .n x .b^2 == 1: return [.a, .b] |
if .a^2 - .n x .b^2 == 1: return [.a, .b] |
||
} |
} |
||
} |
} |
||
for .n in [61, 109, 181, 277] { |
for .n in [61, 109, 181, 277, 8941] { |
||
val .x, .y = .solvePell(.n) |
val .x, .y = .solvePell(.n) |
||
writeln $" |
writeln $"x² - \.n;y² = 1 for:\n\tx = \.x;\n\ty = \.y;" |
||
} |
|||
</lang> |
|||
{{out}} |
{{out}} |
||
<pre>x² - 61y² = 1 for: |
|||
<pre>.x^2 - 61 x .y^2 = 1 for .x = 1766319049 and .y = 226153980 |
|||
x = 1766319049 |
|||
.x^2 - 109 x .y^2 = 1 for .x = 158070671986249 and .y = 15140424455100 |
|||
y = 226153980 |
|||
.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> |
|||
x² - 109y² = 1 for: |
|||
x = 158070671986249 |
|||
y = 15140424455100 |
|||
x² - 181y² = 1 for: |
|||
x = 2469645423824185801 |
|||
y = 183567298683461940 |
|||
x² - 277y² = 1 for: |
|||
x = 159150073798980475849 |
|||
y = 9562401173878027020 |
|||
x² - 8941y² = 1 for: |
|||
x = 2565007112872132129669406439503954211359492684749762901360167370740763715001557789090674216330243703833040774221628256858633287876949448689668281446637464359482677366420261407112316649010675881349744201 |
|||
y = 27126610172119035540864542981075550089190381938849116323732855930990771728447597698969628164719475714805646913222890277024408337458564351161990641948210581361708373955113191451102494265278824127994180 |
|||
</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |