Sum of square and cube digits of an integer are primes: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: refactored) |
m (Added Algol 68) |
||
Line 4: | Line 4: | ||
<br> |
<br> |
||
Sum of square and cube digits of an integer n are primes, where '''n<100''' |
Sum of square and cube digits of an integer n are primes, where '''n<100''' |
||
=={{header|ALGOL 68}}== |
|||
{{libheader|ALGOL 68-primes}} |
|||
<lang algol68>BEGIN # find numbers where the digit sums of the square and cube are prtime # |
|||
INT max number = 99; # maximum number to consider # |
|||
PR read "primes.incl.a68" PR |
|||
[]BOOL prime = PRIMESIEVE ( max number * max number * max number ); |
|||
# returns the sum of the digits of n # |
|||
OP DIGITSUM = ( INT n )INT: |
|||
BEGIN |
|||
INT v := ABS n; |
|||
INT result := v MOD 10; |
|||
WHILE ( v OVERAB 10 ) > 0 DO |
|||
result +:= v MOD 10 |
|||
OD; |
|||
result |
|||
END # DIGITSUM # ; |
|||
FOR i TO max number DO |
|||
INT i2 = i * i; |
|||
IF prime[ DIGITSUM i2 ] THEN |
|||
IF prime[ DIGITSUM ( i * i2 ) ] THEN |
|||
print( ( " ", whole( i, 0 ) ) ) |
|||
FI |
|||
FI |
|||
OD |
|||
END</lang> |
|||
{{out}} |
|||
<pre> |
|||
16 17 25 28 34 37 47 52 64 |
|||
</pre> |
|||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<!--<lang Phix>(phixonline)--> |
<!--<lang Phix>(phixonline)--> |