我已经实现了以下两个函数来确定 n 是否是 fermat 素数(如果它为真则返回 n,如果不是则返回 -1),但它总是返回 -1,无法弄清楚为什么(gc 是一个函数 taht 计算gcd)
fermatPT :: Int -> Int
fermatPT n = fermatPT' n list
where
list = [a | a <- [1..n-1]]
-- | heper function
fermatPT' :: Int -> [Int] -> Int
fermatPT' n l | gc (n, head l) == 1 && fermatTest n (head l) = fermatPT' n (tail l)
| null l = n
| otherwise = -1
where
fermatTest n a = mod (a^(n-1)) n == 1