Primes whose sum of digits is 25: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added personal tag) |
|||
Line 893: | Line 893: | ||
3967 4597 4759 4957 |
3967 4597 4759 4957 |
||
4993</pre> |
4993</pre> |
||
=={{header|Java}}== |
|||
{{trans|Kotlin}} |
|||
<lang java>import java.math.BigInteger; |
|||
public class PrimeSum { |
|||
private static int digitSum(BigInteger bi) { |
|||
int sum = 0; |
|||
while (bi.compareTo(BigInteger.ZERO) > 0) { |
|||
BigInteger[] dr = bi.divideAndRemainder(BigInteger.TEN); |
|||
sum += dr[1].intValue(); |
|||
bi = dr[0]; |
|||
} |
|||
return sum; |
|||
} |
|||
public static void main(String[] args) { |
|||
BigInteger fiveK = BigInteger.valueOf(5_000); |
|||
BigInteger bi = BigInteger.valueOf(2); |
|||
while (bi.compareTo(fiveK) < 0) { |
|||
if (digitSum(bi) == 25) { |
|||
System.out.print(bi); |
|||
System.out.print(" "); |
|||
} |
|||
bi = bi.nextProbablePrime(); |
|||
} |
|||
System.out.println(); |
|||
} |
|||
}</lang> |
|||
{{out}} |
|||
<pre>997 1699 1789 1879 1987 2689 2797 2887 3499 3697 3769 3877 3967 4597 4759 4957 4993 </pre> |
|||
=={{header|JavaScript}}== |
=={{header|JavaScript}}== |