Jump to content

Wieferich primes: Difference between revisions

no edit summary
No edit summary
Line 596:
3,511
</pre>
 
=={{header|Haskell}}==
<lang haskell>isPrime :: Integer -> Bool
isPrime n
|n == 2 = True
|n == 1 = False
|otherwise = null $ filter (\i -> mod n i == 0 ) [2 .. root]
where
root :: Integer
root = toInteger $ floor $ sqrt $ fromIntegral n
 
isWieferichPrime :: Integer -> Bool
isWieferichPrime n = isPrime n && mod ( 2 ^ ( n - 1 ) - 1 ) ( n ^ 2 ) == 0
 
solution :: [Integer]
solution = filter isWieferichPrime [2 .. 5000]
 
main :: IO ( )
main = do
putStrLn "Wieferich primes less than 5000:"
print solution</lang>
{{out}}
<pre>Wieferich primes less than 5000:
[1093,3511]</pre>
 
 
=={{header|Java}}==
Cookies help us deliver our services. By using our services, you agree to our use of cookies.