Anonymous user
Lucas-Lehmer test: Difference between revisions
Updated D entry
(→{{header|Python}}: loop without division) |
(Updated D entry) |
||
Line 419:
<lang d>import std.stdio, std.math, std.bigint;
bool isPrime(in int p) pure nothrow {
if (p < 2 || p % 2 == 0)
return p == 2;
foreach (immutable i; 3 .. cast(uint)(sqrt(cast(real)p)) + 1)
if (p % i == 0)
return false;
Line 428:
}
bool isMersennePrime(in int p)
if (!
return false;
if (p == 2)
return true;
auto s
foreach (immutable _; 3 .. p + 1)
s = (s ^^ 2 - 2) % mp;
return s == 0;
Line 441:
void main() {
foreach (immutable p; 2 .. 2_300)
if
write(
stdout.flush
}
}</lang>
{{out}}
<pre>
With p up to 10_000 it prints:
<pre>
=={{header|DWScript}}==
|