Mersenne primes: Difference between revisions
Content added Content deleted
Line 613: | Line 613: | ||
M50: 2⁷⁷²³²⁹¹⁷ - 1 |
M50: 2⁷⁷²³²⁹¹⁷ - 1 |
||
M51: 2⁸²⁵⁸⁹⁹³³ - 1</pre> |
M51: 2⁸²⁵⁸⁹⁹³³ - 1</pre> |
||
=={{header|Phix}}== |
|||
{{libheader|mpfr}} |
|||
<lang Phix>include mpfr.e |
|||
atom t0 = time() |
|||
mpz mp = mpz_init(), |
|||
bp = mpz_init() |
|||
randstate state = gmp_randinit_mt() |
|||
integer p = 0, count = 0 |
|||
while true do |
|||
mpz_ui_pow_ui(mp,2,p) |
|||
mpz_sub_ui(mp,mp,1) |
|||
if mpz_probable_prime_p(mp, state) then |
|||
string s = iff(time()-t0<1?"":", "&elapsed(time()-t0)) |
|||
printf(1, "2^%d-1%s\n",{p,s}) |
|||
count += 1 |
|||
if count>=17 then exit end if |
|||
end if |
|||
while true do |
|||
p = iff(p>2?p+2:3) |
|||
mpz_set_si(bp,p) |
|||
if mpz_probable_prime_p(bp, state) then exit end if |
|||
end while |
|||
end while |
|||
{mp,bp} = mpz_clear({mp,bp}) |
|||
state = gmp_randclear(state)</lang> |
|||
{{out}} |
|||
<pre> |
|||
2^3-1 |
|||
2^5-1 |
|||
2^7-1 |
|||
2^13-1 |
|||
2^17-1 |
|||
2^19-1 |
|||
2^31-1 |
|||
2^61-1 |
|||
2^89-1 |
|||
2^107-1 |
|||
2^127-1 |
|||
2^521-1 |
|||
2^607-1 |
|||
2^1279-1 |
|||
2^2203-1, 2.5s |
|||
2^2281-1, 2.9s |
|||
2^3217-1, 9.5s |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |