Successive prime differences: Difference between revisions
Content added Content deleted
MaiconSoft (talk | contribs) No edit summary |
MaiconSoft (talk | contribs) |
||
Line 472: | Line 472: | ||
end; |
end; |
||
function |
function Primes(const limit: UInt64): TArray<UInt64>; |
||
var |
var |
||
i: UInt64; |
|||
⚫ | |||
⚫ | |||
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); |
|||
⚫ | |||
while true do |
|||
begin |
begin |
||
SetLength(result, Length(result) + 1); |
|||
p2 := p * p; |
|||
⚫ | |||
⚫ | |||
end; |
|||
⚫ | |||
⚫ | |||
if limit < 2 then |
|||
exit; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
// 2 is the only even prime |
|||
while true do |
|||
Add(2); |
|||
inc(p, 2); |
|||
⚫ | |||
Break; |
|||
⚫ | |||
end; |
|||
⚫ | |||
// set False all even above 2 |
|||
while i <= limit do |
|||
while p < limit do |
|||
begin |
begin |
||
⚫ | |||
⚫ | |||
Add(i); |
|||
⚫ | |||
end; |
end; |
||
end; |
end; |
||
Line 528: | Line 514: | ||
Result := Result + str[i]; |
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 |
|||
⚫ | |||
⚫ | |||
end; |
end; |
||
Line 536: | Line 533: | ||
var |
var |
||
limit, start: UInt64; |
limit, start: UInt64; |
||
c: TArray< |
c: TArray<UInt64>; |
||
i, j: UInt64; |
i, j: UInt64; |
||
Group: array[1..6] of Tlist<string>; |
Group: array[1..6] of Tlist<string>; |
||
Line 545: | Line 542: | ||
limit := Trunc(1e6 - 1); |
limit := Trunc(1e6 - 1); |
||
c := |
c := Primes(limit); |
||
for j := 1 to High(c) do |
|||
j := start; |
|||
while j < limit do |
|||
begin |
begin |
||
if |
if CheckScan(j, c, [2]) then |
||
Group[1].Add(format('(%d,%d)', [j - |
Group[1].Add(format('(%d,%d)', [c[j - 1], c[j]])); |
||
if |
if CheckScan(j, c, [1]) then |
||
Group[2].Add(format('(%d,%d)', [j - 1, j])); |
Group[2].Add(format('(%d,%d)', [c[j - 1], c[j]])); |
||
if |
if j > 1 then |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if ( |
if CheckScan(j, c, [2, 4]) then |
||
Group[4].Add(format('(%d,%d,%d)', [j - 2, j |
Group[4].Add(format('(%d,%d,%d)', [c[j - 2], c[j - 1], c[j]])); |
||
if j |
if CheckScan(j, c, [4, 2]) then |
||
Group[5].Add(format('(%d,%d,%d)', [c[j - 2], c[j - 1], c[j]])); |
|||
⚫ | |||
Group[5].Add(format('(%d,%d,%d)', [j - 4, j, j + 2])); |
|||
if j > |
if j > 2 then |
||
if ( |
if CheckScan(j, c, [6, 4, 2]) then |
||
Group[6].Add(format('(%d,%d,%d,%d)', [j - |
Group[6].Add(format('(%d,%d,%d,%d)', [c[j - 3], c[j - 2], c[j - 1], c[j]])); |
||
inc(j); |
|||
end; |
end; |
||
for i := 1 to 6 do |
for i := 1 to 6 do |
||
begin |
begin |
||
Writeln(Group[i].Count); |
|||
Write(GroupLabel[i], ': first group = ', Group[i].First); |
Write(GroupLabel[i], ': first group = ', Group[i].First); |
||
Writeln(', last group = ', Group[i]. |
Writeln(', last group = ', Group[i].last, ', count = ', Group[i].Count); |
||
Group[i].free; |
Group[i].free; |
||
end; |
end; |
||
readln; |
readln; |
||
end. |
end. |
||
Line 596: | Line 589: | ||
(2, 4): first group = (5,7,11), last group = (999431,999433,999437), count = 1393 |
(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 |
(4, 2): first group = (7,11,13), last group = (997807,997811,997813), count = 1444 |
||
(6, 4, 2): first group = ( |
(6, 4, 2): first group = (31,37,41,43), last group = (997141,997147,997151,997153), count = 306 |
||
</pre> |
</pre> |
||