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

Content added Content deleted
m (Fixed output)
(Added Forth solution)
Line 327: Line 327:
173 5177719
173 5177719
189 6751271
189 6751271
</pre>

=={{header|Forth}}==
{{works with|Gforth}}
<lang forth>: prime? ( n -- flag )
dup 2 < if drop false exit then
dup 2 mod 0= if 2 = exit then
dup 3 mod 0= if 3 = exit then
5
begin
2dup dup * >=
while
2dup mod 0= if 2drop false exit then
2 +
2dup mod 0= if 2drop false exit then
4 +
repeat
2drop true ;

: main
200 0 do
i i i * * 2 + dup prime? if
i 3 .r 9 .r cr
else
drop
then
loop ;

main
bye</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>
</pre>