Prime numbers which contain 123: Difference between revisions

Add CLU
m (→‎{{header|Phix}}: moved the 123 param)
(Add CLU)
Line 139:
Primes with '123' 1-999999: 451
</pre>
 
=={{header|CLU}}==
<lang clu>isqrt = proc (s: int) returns (int)
x0: int := s/2
if x0=0 then return(s) end
x1: int := (x0 + s/x0)/2
while x1 < x0 do
x0 := x1
x1 := (x0 + s/x0)/2
end
return(x0)
end isqrt
 
sieve = proc (n: int) returns (array[bool])
prime: array[bool] := array[bool]$fill(2,n-1,true)
for p: int in int$from_to(2,isqrt(n)) do
if prime[p] then
for c: int in int$from_to_by(p*p,n,p) do
prime[c] := false
end
end
end
return(prime)
end sieve
 
start_up = proc ()
po: stream := stream$primary_output()
count: int := 0
prime: array[bool] := sieve(1000000)
for p: int in array[bool]$indexes(prime) do
if ~prime[p] then continue end
if string$indexs("123", int$unparse(p))=0 then continue end
count := count + 1
if p < 100000 then
stream$putright(po, int$unparse(p), 7)
if count//10=0 then stream$putl(po, "") end
end
end
stream$putl(po, "\nThere are " || int$unparse(count)
|| " primes that contain '123' below 1,000,000.")
end start_up</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
There are 451 primes that contain '123' below 1,000,000.</pre>
 
=={{header|F_Sharp|F#}}==
Line 153 ⟶ 203:
Count to 1 million is 451
</pre>
 
=={{header|Factor}}==
{{works with|Factor|0.99 2021-06-02}}
2,093

edits