Jump to content

Successive prime differences: Difference between revisions

No edit summary
Line 472:
end;
 
function SievePrimes(const limit: UInt64): TArray<BooleanUInt64>;
var
p, p2, i: UInt64;
begin
inc(limit);
SetLength(Result, limit);
FillChar(Result[2], sizeof(Boolean) * limit - 2, 1); // all true except 1,2
FillChar(Result[0], sizeof(Boolean) * 2, 0); // 1,2 false
 
procedure Add(const value: UInt64);
p := 3;
while true do
begin
SetLength(result, Length(result) + 1);
p2 := p * p;
Result[pLength(result) - 1] := Falsevalue;
if p2 >= limit then
breakend;
 
begin
i := p2;
if while ilimit < limit2 dothen
beginexit;
Result[i] := false;
inc(i, 2 * p);
end;
 
// 2 is the only even prime
while true do
beginAdd(2);
inc(p, 2);
if Result[p] then
Break;
end;
end;
 
pi := 3;
// set False all even above 2
pwhile :i <= 4;limit do
while p < limit do
begin
if p2 >= limitIsPrime(i) then
Result[p] := False;
inc(p, 2 Add(i);
inc(limiti, 2);
end;
end;
Line 528 ⟶ 514:
Result := Result + str[i];
end;
end;
 
function CheckScan(index: Integer; p: TArray<UInt64>; pattern: array of Integer): Boolean;
var
i, last: Integer;
begin
last := Length(pattern) - 1;
for i := 0 to last do
if p[index - last + i - 1] + pattern[i] <> p[index - last + i] then
incexit(i, 2 * pFalse);
Result[i] := falseTrue;
end;
 
Line 536 ⟶ 533:
var
limit, start: UInt64;
c: TArray<BooleanUInt64>;
i, j: UInt64;
Group: array[1..6] of Tlist<string>;
Line 545 ⟶ 542:
 
limit := Trunc(1e6 - 1);
c := SievePrimes(limit);
 
startfor j := 3;1 to High(c) do
 
j := start;
while j < limit do
begin
if c[CheckScan(j], andc, c[j - 2]) then
Group[1].Add(format('(%d,%d)', [c[j - 21], c[j]]));
 
if c[CheckScan(j], andc, c[j - 1]) then
Group[2].Add(format('(%d,%d)', [c[j - 1], c[j]]));
 
if (c[j -> 2] and c[j]) and (c[j] and c[j + 2])1 then
end;begin
Group[3].Add(format('(%d,%d,%d)', [j - 2, j, j + 2]));
if ResultCheckScan(j, c, [p2, 2]) then
Group[3].Add(format('(%d,%d,%d)', [c[j - 2], c[j, j- +1], 2c[j]]));
 
if CheckScan(c[j - 2] and, c[j]), and (c[j] and c[j +2, 4]) then
Group[4].Add(format('(%d,%d,%d)', [c[j - 2], c[j, j- +1], 4c[j]]));
 
if CheckScan(j, >c, [4, 2]) then
if Group[5].Add(format('(%d,%d,%d)', [c[j - 42] and, c[j]) and- (c[j1] and, c[j + 2]]) then);
i := p2end;
Group[5].Add(format('(%d,%d,%d)', [j - 4, j, j + 2]));
 
if j > 122 then
if CheckScan(c[j - 12] and, c[j-6]), and (c[j-6], and4, c[j -2]) and (c[j-2] and c[j]) then
Group[6].Add(format('(%d,%d,%d,%d)', [c[j - 123], c[j -6 2], c[j -2 1], c[j]]));
 
inc(j);
end;
 
for i := 1 to 6 do
begin
Writeln(Group[i].Count);
Write(GroupLabel[i], ': first group = ', Group[i].First);
Writeln(', last group = ', Group[i].Lastlast, ', count = ', Group[i].Count);
Group[i].free;
end;
 
readln;
 
end.
 
Line 596 ⟶ 589:
(2, 4): first group = (5,7,11), last group = (999431,999433,999437), count = 1393
(4, 2): first group = (7,11,13), last group = (997807,997811,997813), count = 1444
(6, 4, 2): first group = (731,1337,1741,1943), last group = (997141,997147,997151,997153), count = 337306
</pre>
 
478

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.