modular square root UI
This commit is contained in:
20
app/ModularSquareRootUI.hs
Normal file
20
app/ModularSquareRootUI.hs
Normal file
@@ -0,0 +1,20 @@
|
||||
module ModularSquareRootUI (run) where
|
||||
|
||||
import Utils (askNumber)
|
||||
import ModularSquareRoot (tonelliShanks)
|
||||
|
||||
run :: IO ()
|
||||
run = do
|
||||
putStrLn "Modular square root (Tonelli–Shanks)"
|
||||
putStrLn "Solve x^2 = n (mod p), with p an odd prime."
|
||||
|
||||
n <- askNumber "Enter n:"
|
||||
p <- askNumber "Enter prime modulus p:"
|
||||
|
||||
case tonelliShanks n p of
|
||||
Just x -> do
|
||||
putStrLn "Solution found:"
|
||||
putStrLn ("x = " ++ show x ++ " (mod " ++ show p ++ ")")
|
||||
putStrLn ("Other root: " ++ show ((p - x) `mod` p))
|
||||
Nothing ->
|
||||
putStrLn "No square root exists modulo p."
|
||||
Reference in New Issue
Block a user