Prime numbers which contain 123: Difference between revisions

Added XPL0 example.
(Added XPL0 example.)
Line 517:
 
Found 451 such primes under 1,000,000.
</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 Has123(N); \Return 'true' if N contains sequential digits 1 2 3
int N, C, D;
[C:= 3;
repeat N:= N/10;
D:= rem(0);
if D = C then
[C:= C-1;
if C = 0 then return true;
]
else [C:= 3;
if D = C then C:= 2;
];
until N=0;
return false;
];
 
int N, Count;
[Count:= 0;
for N:= 123 to 1_000_000-1 do
[if Has123(N) then if IsPrime(N) then
[Count:= Count+1;
if N < 100_000 then
[IntOut(0, N);
if rem(Count/10) = 0 then CrLf(0) else ChOut(0, 9\tab\);
];
];
if N = 100_000 then
[CrLf(0); IntOut(0, Count); Text(0, " ^"123^" primes found below 100,000.")];
];
CrLf(0); IntOut(0, Count); Text(0, " ^"123^" primes found below 1,000,000.");
]</lang>
 
{{out}}
<pre>
1123 1231 1237 8123 11239 12301 12323 12329 12343 12347
12373 12377 12379 12391 17123 20123 22123 28123 29123 31123
31231 31237 34123 37123 40123 41231 41233 44123 47123 49123
50123 51239 56123 59123 61231 64123 65123 70123 71233 71237
76123 81233 81239 89123 91237 98123
46 "123" primes found below 100,000.
451 "123" primes found below 1,000,000.
</pre>
 
772

edits