Find prime n such that reversed n is also prime: Difference between revisions
Find prime n such that reversed n is also prime (view source)
Revision as of 22:39, 20 December 2021
, 2 years agoAdd CLU
(Added solution for Action!) |
Not a robot (talk | contribs) (Add CLU) |
||
Line 258:
Count = 34
</pre>
=={{header|CLU}}==
<lang clu>sieve = proc (max: int) returns (array[bool])
prime: array[bool] := array[bool]$fill(0,max+1,true)
prime[0] := false
prime[1] := false
for p: int in int$from_to(2,max/2) do
if ~prime[p] then continue end
for c: int in int$from_to_by(p*p,max,p) do
prime[c] := false
end
end
return(prime)
end sieve
reverse = proc (n: int) returns (int)
r: int := 0
while n>0 do
r := 10*r + n//10
n := n/10
end
return(r)
end reverse
start_up = proc ()
po: stream := stream$primary_output()
prime: array[bool] := sieve(999)
for i: int in int$from_to(2, 500) do
if prime[i] cand prime[reverse(i)] then
stream$puts(po, int$unparse(i) || " ")
end
end
end start_up</lang>
{{out}}
<pre>2 3 5 7 11 13 17 31 37 71 73 79 97 101 107 113 131 149 151 157 167 179 181 191 199 311 313 337 347 353 359 373 383 389</pre>
=={{header|Delphi}}==
|