Carmichael 3 strong pseudoprimes: Difference between revisions
Content added Content deleted
m (→{{header|PARI/GP}}: fix + reformat) |
(Primality test added to the D entry) |
||
Line 79: | Line 79: | ||
=={{header|D}}== |
=={{header|D}}== |
||
<lang d>enum mod = (in int n, in int m) pure nothrow => ((n % m) + m) % m; |
|||
This uses the third D entry of the Sieve of Eratosthenes Task. |
|||
<lang d>import std.stdio, sieve_of_eratosthenes3; |
|||
bool isPrime(in uint n) pure nothrow { |
|||
if (n == 2 || n == 3) |
|||
return true; |
|||
else if (n < 2 || n % 2 == 0 || n % 3 == 0) |
|||
return false; |
|||
for (uint div = 5, inc = 2; div ^^ 2 <= n; |
|||
div += inc, inc = 6 - inc) |
|||
if (n % div == 0) |
|||
return false; |
|||
return true; |
|||
} |
} |
||
void main() { |
void main() { |
||
import std.stdio; |
|||
foreach (immutable p; 2 .. 62) { |
foreach (immutable p; 2 .. 62) { |
||
if (!p. |
if (!p.isPrime) continue; |
||
foreach (immutable h3; 2 .. p) { |
foreach (immutable h3; 2 .. p) { |
||
immutable g = h3 + p; |
immutable g = h3 + p; |
||
Line 95: | Line 104: | ||
continue; |
continue; |
||
immutable q = 1 + (p - 1) * g / d; |
immutable q = 1 + (p - 1) * g / d; |
||
if (!q. |
if (!q.isPrime) continue; |
||
immutable r = 1 + (p * q / h3); |
immutable r = 1 + (p * q / h3); |
||
if (!r. |
if (!r.isPrime || (q * r) % (p - 1) != 1) continue; |
||
writeln(p, " x ", q, " x ", r); |
writeln(p, " x ", q, " x ", r); |
||
} |
} |