Emirp primes: Difference between revisions
Content deleted Content added
Added XPL0 example. |
|||
Line 4,732: | Line 4,732: | ||
The 10,000th emirp is 948349 |
The 10,000th emirp is 948349 |
||
</pre> |
|||
=={{header|XPL0}}== |
|||
<syntaxhighlight lang "XPL0">func IsPrime(N); \Return 'true' if N is prime |
|||
int N, I; |
|||
[if N <= 2 then return N = 2; |
|||
if (N&1) = 0 then \even >2\ return false; |
|||
for I:= 3 to sqrt(N) do |
|||
[if rem(N/I) = 0 then return false; |
|||
I:= I+1; |
|||
]; |
|||
return true; |
|||
]; |
|||
func Reverse(N); \Return the value of N with its digits reversed |
|||
int N, M; |
|||
[M:= 0; |
|||
repeat N:= N/10; |
|||
M:= M*10 + rem(0); |
|||
until N = 0; |
|||
return M; |
|||
]; |
|||
int N, M, Cnt; |
|||
[N:= 13; Cnt:= 0; |
|||
Text(0, "First 20 emirps:^m^j"); |
|||
loop [if IsPrime(N) then |
|||
[M:= Reverse(N); |
|||
if IsPrime(M) and M # N then |
|||
[Cnt:= Cnt+1; |
|||
if Cnt <= 20 then |
|||
[IntOut(0, N); ChOut(0, ^ )]; |
|||
if Cnt = 20 then |
|||
Text(0, "^m^jEmirps between 7700 and 8000:^m^j"); |
|||
if N >= 7700 and N <= 8000 then |
|||
[IntOut(0, N); ChOut(0, ^ )]; |
|||
if Cnt = 10_000 then |
|||
[Text(0, "^m^jThe 10,000 emirp: "); |
|||
IntOut(0, N); |
|||
CrLf(0); |
|||
quit; |
|||
]; |
|||
]; |
|||
]; |
|||
N:= N+2; |
|||
]; |
|||
]</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
First 20 emirps: |
|||
13 17 31 37 71 73 79 97 107 113 149 157 167 179 199 311 337 347 359 389 |
|||
Emirps between 7700 and 8000: |
|||
7717 7757 7817 7841 7867 7879 7901 7927 7949 7951 7963 |
|||
The 10,000 emirp: 948349 |
|||
</pre> |
</pre> |
||