Find prime n such that reversed n is also prime: Difference between revisions
Content added Content deleted
(Added XPL0 example.) |
|||
Line 654: | Line 654: | ||
34 such primes found. |
34 such primes found. |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<lang XPL0>func IsPrime(N); \Return 'true' if N is a prime number |
|||
int N, I; |
|||
[if N <= 1 then return false; |
|||
for I:= 2 to sqrt(N) do |
|||
if rem(N/I) = 0 then return false; |
|||
return true; |
|||
]; |
|||
func Reverse(N); \Return the reverse of the digits in N |
|||
int N, M; |
|||
[M:= 0; |
|||
while N do |
|||
[N:= N/10; |
|||
M:= M*10 + rem(0); |
|||
]; |
|||
return M; |
|||
]; |
|||
int Count, N; |
|||
[Count:= 0; |
|||
for N:= 1 to 499 do |
|||
[if IsPrime(N) & IsPrime(Reverse(N)) then |
|||
[IntOut(0, N); |
|||
Count:= Count+1; |
|||
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\); |
|||
] |
|||
]; |
|||
CrLf(0); |
|||
IntOut(0, Count); |
|||
Text(0, " reversible primes found."); |
|||
]</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 |
|||
34 reversible primes found. |
|||
</pre> |
</pre> |