Primes whose sum of digits is 25: Difference between revisions
Content added Content deleted
(Primes which sum of digits is 25 en BASIC256) |
|||
Line 620: | Line 620: | ||
Exit code: 0 |
Exit code: 0 |
||
</pre> |
</pre> |
||
=={{header|D}}== |
|||
{{trans|C}} |
|||
<lang d>import std.bigint; |
|||
import std.stdio; |
|||
bool isPrime(BigInt n) { |
|||
if (n < 2) { |
|||
return false; |
|||
} |
|||
if (n % 2 == 0) { |
|||
return n == 2; |
|||
} |
|||
if (n % 3 == 0) { |
|||
return n == 3; |
|||
} |
|||
auto i = BigInt(5); |
|||
while (i * i <= n) { |
|||
if (n % i == 0){ |
|||
return false; |
|||
} |
|||
i += 2; |
|||
if (n % i == 0){ |
|||
return false; |
|||
} |
|||
i += 4; |
|||
} |
|||
return true; |
|||
} |
|||
int digitSum(BigInt n) { |
|||
int result; |
|||
while (n > 0) { |
|||
result += n % 10; |
|||
n /= 10; |
|||
} |
|||
return result; |
|||
} |
|||
void main() { |
|||
for (auto n = BigInt(2); n < 5_000; n++) { |
|||
if (n.isPrime && n.digitSum == 25) { |
|||
write(n, ' '); |
|||
} |
|||
} |
|||
writeln; |
|||
}</lang> |
|||
{{out}} |
|||
<pre>997 1699 1789 1879 1987 2689 2797 2887 3499 3697 3769 3877 3967 4597 4759 4957 4993 </pre> |
|||
=={{header|Delphi}}== |
=={{header|Delphi}}== |