我在 Haskell 中有以下代码。我想对给定的数字 n 重复 30 次费马素性检验,但问题是它总是返回 False……我试图解决问题,但我总是得到错误的答案……有什么想法吗?
import System.Random
import System.IO.Unsafe
takeARandomNum n=unsafePerformIO (getStdRandom (randomR (2,n)))
fermatTestA :: (Int, Int) -> Bool
fermatTestA (n, a) =((a^(n-1) `mod` n)==1)
solve :: (Int, Int) -> Bool
solve (n, 1) = fermatTestA (n, takeARandomNum (n-2))
solve (n, maxTest)
| fermatTestA (n, takeARandomNum (n-2)) = (solve (n, (maxTest-1)))
| otherwise = False
fermatTest :: Int ->Bool
fermatTest n = solve (n, 30)