Files
haskell-math/app/ModularSquareRootUI.hs
2026-01-12 13:47:05 +01:00

21 lines
615 B
Haskell
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
module ModularSquareRootUI (run) where
import Utils (askNumber)
import ModularSquareRoot (tonelliShanks)
run :: IO ()
run = do
putStrLn "Modular square root (TonelliShanks)"
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."