Prime numbers which contain 123: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: much more efficient filtering) |
No edit summary |
||
Line 310: | Line 310: | ||
76123 81233 81239 89123 91237 98123 |
76123 81233 81239 89123 91237 98123 |
||
There are 451 primes that contain '123' below 1,000,000.</pre> |
There are 451 primes that contain '123' below 1,000,000.</pre> |
||
=={{header|Delphi}}== |
|||
{{works with|Delphi|6.0}} |
|||
{{libheader|SysUtils,StdCtrls}} |
|||
<syntaxhighlight lang="Delphi"> |
|||
procedure ShowPrimesWith123(Memo: TMemo); |
|||
var N,Sum,Cnt1,Cnt2: integer; |
|||
var NS,S: string; |
|||
begin |
|||
Cnt1:=0; |
|||
Cnt2:=0; |
|||
Sum:=0; |
|||
for N:=123 to 1000000-1 do |
|||
if IsPrime(N) then |
|||
begin |
|||
NS:=IntToStr(N); |
|||
if Pos('123',NS)>0 then |
|||
begin |
|||
Inc(Cnt1); |
|||
if N<100000 then |
|||
begin |
|||
Inc(Cnt2); |
|||
S:=S+Format('%6d',[N]); |
|||
If (Cnt2 mod 8)=0 then S:=S+CRLF; |
|||
end; |
|||
end; |
|||
end; |
|||
Memo.Lines.Add(S); |
|||
Memo.Lines.Add('Count < 100,000 = '+IntToStr(Cnt2)); |
|||
Memo.Lines.Add('Count < 1,000,000 = '+IntToStr(Cnt1)); |
|||
end; |
|||
</syntaxhighlight> |
|||
{{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 |
|||
Count < 100,000 = 46 |
|||
Count < 1,000,000 = 451 |
|||
Elapsed Time: 147.996 ms. |
|||
</pre> |
|||
=={{header|F_Sharp|F#}}== |
=={{header|F_Sharp|F#}}== |