Pierpont primes: Difference between revisions
Content added Content deleted
m (Phix/mpfr) |
|||
Line 1,256: | Line 1,256: | ||
2000th Pierpont prime of the first kind: 1702224134662426018061116932011222570937093650174807121918750428723338890211147039320296240754205680537318845776107057915956535566573559841027244444877454493022783449689509569107393738917120492483994302725479684822283929715327187974256253064796234576415398735760543848603844607</pre> |
2000th Pierpont prime of the first kind: 1702224134662426018061116932011222570937093650174807121918750428723338890211147039320296240754205680537318845776107057915956535566573559841027244444877454493022783449689509569107393738917120492483994302725479684822283929715327187974256253064796234576415398735760543848603844607</pre> |
||
=={{header|Lua}}== |
|||
<lang lua>local function isprime(n) |
|||
if n < 2 then return false end |
|||
if n % 2 == 0 then return n==2 end |
|||
if n % 3 == 0 then return n==3 end |
|||
local f, limit = 5, math.sqrt(n) |
|||
for f = 5, limit, 6 do |
|||
if n % f == 0 then return false end |
|||
if n % (f+2) == 0 then return false end |
|||
end |
|||
return true |
|||
end |
|||
local function s3iter() |
|||
local s, i2, i3 = {1}, 1, 1 |
|||
return function() |
|||
local n2, n3, val = 2*s[i2], 3*s[i3], s[#s] |
|||
s[#s+1] = math.min(n2, n3) |
|||
i2, i3 = i2 + (n2<=n3 and 1 or 0), i3 + (n2>=n3 and 1 or 0) |
|||
return val |
|||
end |
|||
end |
|||
local function pierpont(n) |
|||
local list1, list2, s3next = {}, {}, s3iter() |
|||
while #list1 < n or #list2 < n do |
|||
local s3 = s3next() |
|||
if #list1 < n then |
|||
if isprime(s3+1) then list1[#list1+1] = s3+1 end |
|||
end |
|||
if #list2 < n then |
|||
if isprime(s3-1) then list2[#list2+1] = s3-1 end |
|||
end |
|||
end |
|||
return list1, list2 |
|||
end |
|||
local N = 50 |
|||
local p1, p2 = pierpont(N) |
|||
print("First 50 Pierpont primes of the first kind:") |
|||
for i, p in ipairs(p1) do |
|||
io.write(string.format("%8d%s", p, (i%10==0 and "\n" or " "))) |
|||
end |
|||
print() |
|||
print("First 50 Pierpont primes of the second kind:") |
|||
for i, p in ipairs(p2) do |
|||
io.write(string.format("%8d%s", p, (i%10==0 and "\n" or " "))) |
|||
end</lang> |
|||
{{out}} |
|||
<pre>First 50 Pierpont primes of the first kind: |
|||
2 3 5 7 13 17 19 37 73 97 |
|||
109 163 193 257 433 487 577 769 1153 1297 |
|||
1459 2593 2917 3457 3889 10369 12289 17497 18433 39367 |
|||
52489 65537 139969 147457 209953 331777 472393 629857 746497 786433 |
|||
839809 995329 1179649 1492993 1769473 1990657 2654209 5038849 5308417 8503057 |
|||
First 50 Pierpont primes of the second kind: |
|||
2 3 5 7 11 17 23 31 47 53 |
|||
71 107 127 191 383 431 647 863 971 1151 |
|||
2591 4373 6143 6911 8191 8747 13121 15551 23327 27647 |
|||
62207 73727 131071 139967 165887 294911 314927 442367 472391 497663 |
|||
524287 786431 995327 1062881 2519423 10616831 17915903 18874367 25509167 30233087</pre> |
|||
=={{header|Perl}}== |
=={{header|Perl}}== |