Prime triplets: Difference between revisions
Content added Content deleted
(Added PL/0) |
No edit summary |
||
Line 366: | Line 366: | ||
next p |
next p |
||
end</syntaxhighlight> |
end</syntaxhighlight> |
||
=={{header|Delphi}}== |
|||
{{works with|Delphi|6.0}} |
|||
{{libheader|SysUtils,StdCtrls}} |
|||
<syntaxhighlight lang="Delphi"> |
|||
function IsPrime(N: int64): boolean; |
|||
{Fast, optimised prime test} |
|||
var I,Stop: int64; |
|||
begin |
|||
if (N = 2) or (N=3) then Result:=true |
|||
else if (n <= 1) or ((n mod 2) = 0) or ((n mod 3) = 0) then Result:= false |
|||
else |
|||
begin |
|||
I:=5; |
|||
Stop:=Trunc(sqrt(N+0.0)); |
|||
Result:=False; |
|||
while I<=Stop do |
|||
begin |
|||
if ((N mod I) = 0) or ((N mod (I + 2)) = 0) then exit; |
|||
Inc(I,6); |
|||
end; |
|||
Result:=True; |
|||
end; |
|||
end; |
|||
procedure ShowTriple026Prime(Memo: TMemo); |
|||
var N,Sum,Cnt: integer; |
|||
var NS,S: string; |
|||
begin |
|||
Cnt:=0; |
|||
S:=''; |
|||
for N:=1 to 5500-1 do |
|||
if IsPrime(N) then |
|||
if IsPrime(N+2) and IsPrime(N+6) then |
|||
begin |
|||
Inc(Cnt); |
|||
S:=S+Format('%6d%6d%6d',[N,N+2,N+6]); |
|||
S:=S+CRLF; |
|||
end; |
|||
Memo.Lines.Add(' P P+2 P+6'); |
|||
Memo.Lines.Add('------------------'); |
|||
Memo.Lines.Add(S); |
|||
Memo.Lines.Add('Count = '+IntToStr(Cnt)); |
|||
end; |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
P P+2 P+6 |
|||
------------------ |
|||
5 7 11 |
|||
11 13 17 |
|||
17 19 23 |
|||
41 43 47 |
|||
101 103 107 |
|||
107 109 113 |
|||
191 193 197 |
|||
227 229 233 |
|||
311 313 317 |
|||
347 349 353 |
|||
461 463 467 |
|||
641 643 647 |
|||
821 823 827 |
|||
857 859 863 |
|||
881 883 887 |
|||
1091 1093 1097 |
|||
1277 1279 1283 |
|||
1301 1303 1307 |
|||
1427 1429 1433 |
|||
1481 1483 1487 |
|||
1487 1489 1493 |
|||
1607 1609 1613 |
|||
1871 1873 1877 |
|||
1997 1999 2003 |
|||
2081 2083 2087 |
|||
2237 2239 2243 |
|||
2267 2269 2273 |
|||
2657 2659 2663 |
|||
2687 2689 2693 |
|||
3251 3253 3257 |
|||
3461 3463 3467 |
|||
3527 3529 3533 |
|||
3671 3673 3677 |
|||
3917 3919 3923 |
|||
4001 4003 4007 |
|||
4127 4129 4133 |
|||
4517 4519 4523 |
|||
4637 4639 4643 |
|||
4787 4789 4793 |
|||
4931 4933 4937 |
|||
4967 4969 4973 |
|||
5231 5233 5237 |
|||
5477 5479 5483 |
|||
Count = 43 |
|||
Elapsed Time: 13.263 ms. |
|||
</pre> |
|||