Pierpont primes: Difference between revisions
Thundergnat (talk | contribs) (New draft task and Perl 6 entry) |
Thundergnat (talk | contribs) m (fix typo) |
||
Line 18: | Line 18: | ||
:* Use the routine to find and display here, on this page, the first '''50 Pierpont primes of the second kind''' |
:* Use the routine to find and display here, on this page, the first '''50 Pierpont primes of the second kind''' |
||
:* If your language supports large integers, find and show here, on this page, the '''250<sup>th</sup> Pierpont prime of the first kind''' and the '''250<sup>th</sup> Pierpont |
:* If your language supports large integers, find and show here, on this page, the '''250<sup>th</sup> Pierpont prime of the first kind''' and the '''250<sup>th</sup> Pierpont prime of the second kind'''. |
||
Revision as of 16:11, 18 August 2019
A Pierpont prime is a prime number of the form: 2u3v + 1 for some non-negative integers u and v .
A Pierpont prime of the second kind is a prime number of the form: 2u3v - 1 for some non-negative integers u and v .
The term "Pierpont primes" is generally understood to mean the first definition, but will be called "Pierpont primes of the first kind" on this page to distinguish them.
- Task
- Write a routine (function, procedure, whatever) to find Pierpont primes of the first & second kinds.
- Use the routine to find and display here, on this page, the first 50 Pierpont primes of the first kind.
- Use the routine to find and display here, on this page, the first 50 Pierpont primes of the second kind
- If your language supports large integers, find and show here, on this page, the 250th Pierpont prime of the first kind and the 250th Pierpont prime of the second kind.
- See also
Perl 6
<lang perl6>use ntheory:from<Perl5> <is_prime>;
sub pierpont ($type is copy = 1) {
gather { fail "Unknown type: $type Must be one of 1 (default) or 2" if $type !== 1|2; take 2 if $type == 1; $type = -1 if $type == 2; state $po3 = 0; state $add-one = 3; state @iterators = [2,4,8 … *].iterator, [3,9,27 … *].iterator;
my @head = @iterators».pull-one;
loop { my $key = @head[*]»[0].pairs.min( *.value ).key; my $min = @head[$key]; @head[$key] = @iterators[$key].pull-one;
take $min + $type if "{$min + $type}".&is_prime;
if $min >= $add-one { ++$po3; @iterators.push: ([|((2,4,8).map: * * 3 ** $po3) … *]).iterator; @head[+@iterators - 1] = @iterators[+@iterators - 1].pull-one; $add-one *= 3; } } }
}
say "First 50 Pierpont primes of the first kind:\n" ~ pierpont[^50].rotor(10)».fmt('%8d').join: "\n";
say "\nFirst 50 Pierpont primes of the second kind:\n" ~ pierpont(2)[^50].rotor(10)».fmt('%8d').join: "\n";
say "\n250th Pierpont prime of the first kind: " ~ pierpont[249];
say "\n250th Pierpont prime of the second kind: " ~ pierpont(2)[249];</lang>
- Output:
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 250th Pierpont prime of the first kind: 62518864539857068333550694039553 250th Pierpont prime of the second kind: 4111131172000956525894875083702271