Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
32
Task/Pells-equation/Sidef/pells-equation.sidef
Normal file
32
Task/Pells-equation/Sidef/pells-equation.sidef
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
func solve_pell(n) {
|
||||
|
||||
var x = n.isqrt
|
||||
var y = x
|
||||
var z = 1
|
||||
var r = 2*x
|
||||
|
||||
var (e1, e2) = (1, 0)
|
||||
var (f1, f2) = (0, 1)
|
||||
|
||||
loop {
|
||||
|
||||
y = (r*z - y)
|
||||
z = floor((n - y*y) / z)
|
||||
r = floor((x + y) / z)
|
||||
|
||||
(e1, e2) = (e2, r*e2 + e1)
|
||||
(f1, f2) = (f2, r*f2 + f1)
|
||||
|
||||
var A = (e2 + x*f2)
|
||||
var B = f2
|
||||
|
||||
if (A**2 - n*B**2 == 1) {
|
||||
return (A, B)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for n in [61, 109, 181, 277] {
|
||||
var (x, y) = solve_pell(n)
|
||||
printf("x^2 - %3d*y^2 = 1 for x = %-21s and y = %s\n", n, x, y)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue