Sum of square and cube digits of an integer are primes: Difference between revisions
Sum of square and cube digits of an integer are primes (view source)
Revision as of 17:41, 19 June 2023
, 11 months agoCreated Nim solution.
No edit summary |
(Created Nim solution.) |
||
Line 725:
52
64</pre>
=={{header|Nim}}==
<syntaxhighlight lang="Nim">const Primes = {2, 3, 5, 7, 11, 13, 17, 19}
func digitSum(n: Positive): int =
## Return the sum of digits of "n".
var n = n.Natural
while n != 0:
result += n mod 10
n = n div 10
for n in 5..99:
let n² = n * n
if digitSum(n²) in Primes and digitSum(n * n²) in Primes:
stdout.write n, ' '
echo()
</syntaxhighlight>
{{out}}
<pre>16 17 25 28 34 37 47 52 64 </pre>
=={{header|OCaml}}==
|