Prime numbers which contain 123: Difference between revisions
Content added Content deleted
m (→{{header|Sidef}}: minor fix when `upto` is not a power of `base`) |
(→{{header|ALGOL 68}}: Use ALGOL 68-primes) |
||
Line 10: | Line 10: | ||
=={{header|ALGOL 68}}== |
=={{header|ALGOL 68}}== |
||
{{libheader|ALGOL 68-primes}} |
|||
<lang algol68>BEGIN # find primes whose decimal representation contains 123 # |
<lang algol68>BEGIN # find primes whose decimal representation contains 123 # |
||
INT max prime = 1 000 000; |
INT max prime = 1 000 000; |
||
# sieve the primes to max prime # |
# sieve the primes to max prime # |
||
PR read "primes.incl.a68" PR |
|||
[ 1 : max prime ]BOOL prime; |
|||
[]BOOL prime = PRIMESIEVE max prime; |
|||
FOR i FROM 3 BY 2 TO UPB prime DO prime[ i ] := TRUE OD; |
|||
FOR i FROM 4 BY 2 TO UPB prime DO prime[ i ] := FALSE OD; |
|||
FOR i FROM 3 BY 2 TO ENTIER sqrt( UPB prime ) DO |
|||
IF prime[ i ] THEN FOR s FROM i * i BY i + i TO UPB prime DO prime[ s ] := FALSE OD FI |
|||
OD; |
|||
# find the appropriate primes # |
# find the appropriate primes # |
||
# as observed by the Wren sample, the primes must have a least 4 digits # |
# as observed by the Wren sample, the primes must have a least 4 digits # |
||
Line 57: | Line 53: | ||
Found 451 "123" primes below 1000000 |
Found 451 "123" primes below 1000000 |
||
</pre> |
</pre> |
||
=={{header|AWK}}== |
=={{header|AWK}}== |
||
<lang AWK> |
<lang AWK> |