Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
15
Task/Pells-equation/Haskell/pells-equation.hs
Normal file
15
Task/Pells-equation/Haskell/pells-equation.hs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
pell :: Integer -> (Integer, Integer)
|
||||
pell n = go (x, 1, x * 2, 1, 0, 0, 1)
|
||||
where
|
||||
x = floor $ sqrt $ fromIntegral n
|
||||
go (y, z, r, e1, e2, f1, f2) =
|
||||
let y' = r * z - y
|
||||
z' = (n - y' * y') `div` z
|
||||
r' = (x + y') `div` z'
|
||||
(e1', e2') = (e2, e2 * r' + e1)
|
||||
(f1', f2') = (f2, f2 * r' + f1)
|
||||
(a, b) = (f2', e2')
|
||||
(b', a') = (a, a * x + b)
|
||||
in if a' * a' - n * b' * b' == 1
|
||||
then (a', b')
|
||||
else go (y', z', r', e1', e2', f1', f2')
|
||||
Loading…
Add table
Add a link
Reference in a new issue