n がフェルマー素数であるかどうかを確立するために次の 2 つの関数を実装しました (真の場合は n を返し、そうでない場合は -1 を返します)、常に -1 を返します。理由がわかりません (gc は計算する関数です)。 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