Pierpont primes: Difference between revisions

Content added Content deleted
Line 1,376:
62207 73727 131071 139967 165887 294911 314927 442367 472391 497663
524287 786431 995327 1062881 2519423 10616831 17915903 18874367 25509167 30233087</pre>
 
=={{header|Nim}}==
<lang Nim>import math, strutils
 
func isPrime(n: int): bool =
## Check if "n" is prime by trying successive divisions.
## "n" is supposed not to be a multiple of 2 or 3.
var d = 5
var delta = 2
while d <= int(sqrt(n.toFloat)):
if n mod d == 0: return false
inc d, delta
delta = 6 - delta
result = true
 
func isProduct23(n: int): bool =
## Check if "n" has only 2 and 3 for prime divisors
## (i.e. that "n = 2^u * 3^v").
var n = n
while (n and 1) == 0: n = n shr 1
while n mod 3 == 0: n = n div 3
result = n == 1
 
iterator pierpont(maxCount: Positive; k: int): int =
## Yield the Pierpoint primes of first or second kind according
## to the value of "k" (+1 for first kind, -1 for second kind).
yield 2
yield 3
var n = 5
var delta = 2 # 2 and 4 alternatively to skip the multiples of 2 and 3.
yield n
var count = 3
while count < maxCount:
inc n, delta
delta = 6 - delta
if isProduct23(n - k) and isPrime(n):
inc count
yield n
 
template pierpont1*(maxCount: Positive): int = pierpont(maxCount, +1)
template pierpont2*(maxCount: Positive): int = pierpont(maxCount, -1)
 
 
when isMainModule:
 
echo "First 50 Pierpont primes of the first kind:"
var count = 0
for n in pierpont1(50):
stdout.write ($n).align(9)
inc count
if count mod 10 == 0: stdout.write '\n'
 
echo ""
echo "First 50 Pierpont primes of the second kind:"
count = 0
for n in pierpont2(50):
stdout.write ($n).align(9)
inc count
if count mod 10 == 0: stdout.write '\n'</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}}==