Mersenne primes: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 557: | Line 557: | ||
</pre> |
</pre> |
||
Using this approach, the Celeron machine (dual core) takes ~180 seconds to reach M<sub>9941</sub> and ~270 seconds to reach M<sub>11213</sub>. |
Using this approach, the Celeron machine (dual core) takes ~180 seconds to reach M<sub>9941</sub> and ~270 seconds to reach M<sub>11213</sub>. |
||
=={{header|Haskell}}== |
|||
<lang haskell>import Data.List (foldr) |
|||
import Data.Numbers.Primes (primes) |
|||
import Text.Printf (printf) |
|||
lucasLehmer :: Int -> Bool |
|||
lucasLehmer p = go 4 == 0 |
|||
where |
|||
go s = foldr (\a b -> (b ^ 2 - 2) `mod` m) s [1..p - 2] |
|||
m = 2 ^ p - 1 |
|||
main = mapM_ (printf "M %d\n") $ take 20 mersenne |
|||
where |
|||
mersenne = filter lucasLehmer primes</lang> |
|||
{{out}} |
|||
<pre> |
|||
M 3 |
|||
M 5 |
|||
M 7 |
|||
M 13 |
|||
M 17 |
|||
M 19 |
|||
M 31 |
|||
M 61 |
|||
M 89 |
|||
M 107 |
|||
M 127 |
|||
M 521 |
|||
M 607 |
|||
M 1279 |
|||
M 2203 |
|||
M 2281 |
|||
M 3217 |
|||
M 4253 |
|||
M 4423 |
|||
M 9689 |
|||
</pre> |
|||
=={{header|Java}}== |
=={{header|Java}}== |
||
{{trans|Kotlin}} |
{{trans|Kotlin}} |