Find prime numbers of the form n*n*n+2: Difference between revisions

Content added Content deleted
(Add Plain English example)
(Added Algol 68)
Line 68: Line 68:
173 5177719
173 5177719
189 6751271</pre>
189 6751271</pre>

=={{header|ALGOL 68}}==
<lang algol68>BEGIN # Find n such that n^3 + 2 is a prime for n < 200 #
FOR n TO 199 DO
INT candidate = ( n * n * n ) + 2;
# there will only be 199 candidates, so a primality check by trial #
# division should be OK #
BOOL is prime := TRUE;
FOR f FROM 2 TO ENTIER sqrt( candidate )
WHILE is prime := candidate MOD f /= 0
DO SKIP OD;
IF is prime THEN
# n^3 + 2 is prime #
print( ( whole( n, -4 ), ": ", whole( candidate, -8 ), newline ) )
FI
OD
END</lang>
{{out}}
<pre>
1: 3
3: 29
5: 127
29: 24391
45: 91127
63: 250049
65: 274627
69: 328511
71: 357913
83: 571789
105: 1157627
113: 1442899
123: 1860869
129: 2146691
143: 2924209
153: 3581579
171: 5000213
173: 5177719
189: 6751271
</pre>


=={{header|AWK}}==
=={{header|AWK}}==
Line 120: Line 159:
Prime numbers 1-200 of the form n*n*n+2: 19
Prime numbers 1-200 of the form n*n*n+2: 19
</pre>
</pre>

=={{header|C}}==
=={{header|C}}==
{{trans|Wren}}
{{trans|Wren}}