Pierpont primes: Difference between revisions
Content deleted Content added
→{{header|Ruby}}: Add Ruby |
No edit summary |
||
Line 1,716: | Line 1,716: | ||
62207 73727 131071 139967 165887 294911 314927 442367 472391 497663 |
62207 73727 131071 139967 165887 294911 314927 442367 472391 497663 |
||
524287 786431 995327 1062881 2519423 10616831 17915903 18874367 25509167 30233087</pre> |
524287 786431 995327 1062881 2519423 10616831 17915903 18874367 25509167 30233087</pre> |
||
=={{header|M2000 Interpreter}}== |
|||
{{trans|freebasic}} |
|||
<lang M2000Interpreter> |
|||
Module Pierpoint_Primes { |
|||
Form 80 |
|||
Set Fast ! |
|||
const NPP=50 |
|||
dim pier(1 to 2, 1 to NPP), np(1 to 2) = 0 |
|||
def long x = 1, j |
|||
while np(1)<=NPP or np(2)<=NPP |
|||
x++ : if x mod 100&=0& then print np(), x: refresh |
|||
j = @is_pierpont(x) |
|||
if j>0 Else Continue |
|||
if j mod 2 = 1 then np(1)++ :if np(1) <= NPP then pier(1, np(1)) = x |
|||
if j > 1 then np(2)++ : if np(2) <= NPP then pier(2, np(2)) = x |
|||
end while |
|||
print "First ";NPP;" Pierpont primes of the first kind:" |
|||
for j = 1 to NPP |
|||
print pier(2, j), |
|||
next j |
|||
if pos>0 then print |
|||
print "First ";NPP;" Pierpont primes of the second kind:" |
|||
for j = 1 to NPP |
|||
print pier(1, j), |
|||
next j |
|||
if pos>0 then print |
|||
Set Fast |
|||
function is_prime( n as decimal) |
|||
if n < 2 then = false : exit function |
|||
if n <4 then = true : exit function |
|||
if n mod 2 = 0 then = false : exit function |
|||
local i as long |
|||
for i = 3 to int(sqrt(n))+1 step 2 |
|||
if n mod i = 0 then = false : exit function |
|||
next i |
|||
= true |
|||
end function |
|||
function is_23(n as long ) |
|||
while n mod 2 = 0 |
|||
n = n div 2 |
|||
end while |
|||
while n mod 3 = 0 |
|||
n = n div 3 |
|||
end while |
|||
if n = 1 then = true else = false |
|||
end function |
|||
function is_pierpont( n as long ) |
|||
if not @is_prime(n) then = 0& : exit function 'not prime |
|||
Local p1 = @is_23(n+1), p2 = @is_23(n-1) |
|||
if p1 and p2 then = 3 : exit function 'pierpont prime of both kinds |
|||
if p1 then = 1 : exit function 'pierpont prime of the 1st kind |
|||
if p2 then = 2 : exit function 'pierpont prime of the 2nd kind |
|||
= 0 'prime, but not pierpont |
|||
end function |
|||
} |
|||
Pierpoint_Primes |
|||
</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|Mathematica}}/{{header|Wolfram Language}}== |
=={{header|Mathematica}}/{{header|Wolfram Language}}== |