Quadrat special primes: Difference between revisions

no edit summary
No edit summary
Line 362:
loop
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 QuadratSpecialPrimes(Memo: TMemo);
var Q,P,Cnt: integer;
var IA: TIntegerDynArray;
begin
Memo.Lines.Add('Count Prime1 Prime2 Gap Sqrt');
Memo.Lines.Add('---------------------------------');
Cnt:=0;
Q:=2;
for P:=3 to 16000-1 do
if IsPrime(P) then
begin
if frac(sqrt(P - Q))=0 then
begin
Inc(Cnt);
Memo.Lines.Add(Format('%5D%7D%8D%7D%6.1f',[Cnt,Q,P,P-Q,Sqrt(P-Q)]));
Q:=P;
end;
end;
Memo.Lines.Add('Count = '+IntToStr(Cnt));
end;
 
 
</syntaxhighlight>
{{out}}
<pre>
Count Prime1 Prime2 Gap Sqrt
---------------------------------
1 2 3 1 1.0
2 3 7 4 2.0
3 7 11 4 2.0
4 11 47 36 6.0
5 47 83 36 6.0
6 83 227 144 12.0
7 227 263 36 6.0
8 263 587 324 18.0
9 587 911 324 18.0
10 911 947 36 6.0
11 947 983 36 6.0
12 983 1019 36 6.0
13 1019 1163 144 12.0
14 1163 1307 144 12.0
15 1307 1451 144 12.0
16 1451 1487 36 6.0
17 1487 1523 36 6.0
18 1523 1559 36 6.0
19 1559 2459 900 30.0
20 2459 3359 900 30.0
21 3359 4259 900 30.0
22 4259 4583 324 18.0
23 4583 5483 900 30.0
24 5483 5519 36 6.0
25 5519 5843 324 18.0
26 5843 5879 36 6.0
27 5879 6203 324 18.0
28 6203 6779 576 24.0
29 6779 7103 324 18.0
30 7103 7247 144 12.0
31 7247 7283 36 6.0
32 7283 7607 324 18.0
33 7607 7643 36 6.0
34 7643 8219 576 24.0
35 8219 8363 144 12.0
36 8363 10667 2304 48.0
37 10667 11243 576 24.0
38 11243 11279 36 6.0
39 11279 11423 144 12.0
40 11423 12323 900 30.0
41 12323 12647 324 18.0
42 12647 12791 144 12.0
43 12791 13367 576 24.0
44 13367 13691 324 18.0
45 13691 14591 900 30.0
46 14591 14627 36 6.0
47 14627 14771 144 12.0
48 14771 15671 900 30.0
Count = 48
Elapsed Time: 111.233 ms.
</pre>
 
 
=={{header|F_Sharp|F#}}==
465

edits