Primality by trial division: Difference between revisions

No edit summary
Line 1,474:
<syntaxhighlight lang="d">import std.stdio, std.algorithm, std.range, std.math;
 
bool isPrime1(T)(in intT n) pure nothrow {
if// (nSimple == 2)Version
if (n == 2)
return true;
if (n <= 1 || (n & 1) == 0)
return false;
 
for(intT i = 3; i <= real(n).sqrt; i += 2)
if (n % i == 0)
return false;
return true;
}
 
 
void main() {
Line 1,491 ⟶ 1,495:
{{out}}
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37]
 
===Version with excluded multiplies of 2 and 3===
Same output.
117

edits