Lucas-Lehmer test: Difference between revisions
Content added Content deleted
(+Oz) |
No edit summary |
||
Line 150:
int main()
{
{
{
}
}
}
bool is_mersenne_prime(mpz_class p)
{
{
mpz_class s(4);
++i )
{
}
}
}
mpz_class pow2(mpz_class exp)
{
mpz_class ret(2);
ret *= mpz_class(2);
}
</pre>
Line 345:
{Application.exit 0}
end</ocaml>
=={{header|Pop11}}==
Checking large numbers takes a lot of time so we limit p to
be smaller than 1000.
<pre>
define Lucas_Lehmer_Test(p);
lvars mp = 2**p - 1, sn = 4, i;
for i from 2 to p - 1 do
(sn*sn - 2) rem mp -> sn;
endfor;
sn = 0;
enddefine;
lvars p = 3;
printf('M2', '%p\n');
while p < 1000 do
if Lucas_Lehmer_Test(p) then
printf('M', '%p');
printf(p, '%p\n');
endif;
p + 2 -> p;
endwhile;
</pre>
The output (obtained in few seconds) is:
<pre>
M2
M3
M5
M7
M13
M17
M19
M31
M61
M89
M107
M127
M521
M607
<pre>
=={{header|Python}}==
from sys import stdout
|