Find prime n such that reversed n is also prime: Difference between revisions
Content deleted Content added
No edit summary |
No edit summary |
||
Line 657:
print</syntaxhighlight>
{{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|Go}}==
Line 1,147 ⟶ 1,083:
{{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|Pascal}}==
==={{header|Free Pascal}}===
<syntaxhighlight lang="pascal">
Type Tboolarr = array Of boolean;
Const MAX = 1000;
Function SieveOfEratosthenes(limit: Integer): Tboolarr;
Var
sieve: Tboolarr;
i, j: Integer;
Begin
SetLength(sieve, limit + 1);
sieve[2] := True;
For i := 3 To limit Do
sieve[i] := (i Mod 2 <> 0);
For i := 3 To Trunc(Sqrt(limit)) Do
Begin
If sieve[i] Then
Begin
j := i * i;
While j <= limit Do
Begin
sieve[j] := False;
Inc(j, 2 * i);
End;
End;
End;
SieveOfEratosthenes := sieve;
End;
Function ReverseNumber(number: Integer): Integer;
Var
reversed: Integer;
Begin
reversed := 0;
While number <> 0 Do
Begin
reversed := reversed * 10 + (number Mod 10);
number := number Div 10;
End;
ReverseNumber := reversed;
End;
Var
primes: Tboolarr;
i: Integer;
Begin
primes := SieveOfEratosthenes(MAX);
For i := 2 To 500 Do
Begin
If primes[i] And Primes[ReverseNumber(i)] Then
Write(i,' ');
End;
End.
</syntaxhighlight>
{{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|Perl}}==
|