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

Add CLU
(Add CLU)
Line 311:
189 6751271
</pre>
 
=={{header|CLU}}==
<lang clu>is_prime = proc (n: int) returns (bool)
if n<2 then return(false) end
if n//2=0 then return(n=2) end
if n//3=0 then return(n=3) end
d: int := 5
while d*d <= n do
if n//d=0 then return(false) end
d := d+2
if n//d=0 then return(false) end
d := d+4
end
return(true)
end is_prime
 
n3plus2_primes = iter (max: int) yields (int,int)
for n: int in int$from_to(1, max) do
p: int := n**3 + 2
if is_prime(p) then yield(n,p) end
end
end n3plus2_primes
 
start_up = proc ()
po: stream := stream$primary_output()
for n, p: int in n3plus2_primes(200) do
stream$puts(po, "n = ")
stream$putright(po, int$unparse(n), 3)
stream$puts(po, " => n^3 + 2 = ")
stream$putright(po, int$unparse(p), 7)
stream$putl(po, "")
end
end start_up</lang>
{{out}}
<pre>n = 1 => n^3 + 2 = 3
n = 3 => n^3 + 2 = 29
n = 5 => n^3 + 2 = 127
n = 29 => n^3 + 2 = 24391
n = 45 => n^3 + 2 = 91127
n = 63 => n^3 + 2 = 250049
n = 65 => n^3 + 2 = 274627
n = 69 => n^3 + 2 = 328511
n = 71 => n^3 + 2 = 357913
n = 83 => n^3 + 2 = 571789
n = 105 => n^3 + 2 = 1157627
n = 113 => n^3 + 2 = 1442899
n = 123 => n^3 + 2 = 1860869
n = 129 => n^3 + 2 = 2146691
n = 143 => n^3 + 2 = 2924209
n = 153 => n^3 + 2 = 3581579
n = 171 => n^3 + 2 = 5000213
n = 173 => n^3 + 2 = 5177719
n = 189 => n^3 + 2 = 6751271</pre>
 
=={{header|Delphi}}==
2,094

edits