Successive prime differences: Difference between revisions
→{{header|Delphi}}
MaiconSoft (talk | contribs) No edit summary |
MaiconSoft (talk | contribs) |
||
Line 472:
end;
function
var
begin▼
inc(limit);▼
procedure Add(const value: UInt64);
p := 3;▼
begin
SetLength(result, Length(result) + 1);
if p2 >= limit then▼
▲begin
i := p2;▼
if
Result[i] := false;▼
inc(i, 2 * p);▼
end;▼
// 2 is the only even prime
if Result[p] then▼
end;▼
begin
▲ Result[p] := False;
end;
end;
Line 528 ⟶ 514:
Result := Result + str[i];
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
end;
Line 536 ⟶ 533:
var
limit, start: UInt64;
c: TArray<
i, j: UInt64;
Group: array[1..6] of Tlist<string>;
Line 545 ⟶ 542:
limit := Trunc(1e6 - 1);
c :=
begin
if
Group[1].Add(format('(%d,%d)', [c[j -
if
Group[2].Add(format('(%d,%d)', [c[j - 1], c[j]]));
if
Group[3].Add(format('(%d,%d,%d)', [j - 2, j, j + 2]));▼
if CheckScan(
Group[4].Add(format('(%d,%d,%d)', [c[j - 2], c[j
if CheckScan(j,
if j >
if CheckScan(
Group[6].Add(format('(%d,%d,%d,%d)', [c[j -
end;
for i := 1 to 6 do
begin
Write(GroupLabel[i], ': first group = ', Group[i].First);
Writeln(', last group = ', Group[i].
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 = (
</pre>
|