Penta-power prime seeds: Difference between revisions
Thundergnat (talk | contribs) (Change descriptions to match task rename) |
(Added Wren) |
||
Line 51: | Line 51: | ||
nine million is the 71st: 9,100,671 |
nine million is the 71st: 9,100,671 |
||
ten million is the 72nd: 10,347,035</pre> |
ten million is the 72nd: 10,347,035</pre> |
||
=={{header|Wren}}== |
|||
{{libheader|Wren-gmp}} |
|||
{{libheader|Wren-fmt}} |
|||
<lang ecmascript>import "./gmp" for Mpz |
|||
import "./fmt" for Fmt |
|||
var p = Mpz.new() |
|||
var q = Mpz.one |
|||
var isPentaPowerPrimeSeed = Fn.new { |n| |
|||
p.setUi(n) |
|||
var k = n + 1 |
|||
return (q + k).probPrime(15) > 0 && |
|||
(p + k).probPrime(15) > 0 && |
|||
(p.mul(n) + k).probPrime(15) > 0 && |
|||
(p.mul(n) + k).probPrime(15) > 0 && |
|||
(p.mul(n) + k).probPrime(15) > 0 |
|||
} |
|||
var ppps = [] |
|||
var n = 1 |
|||
while (ppps.count < 30) { |
|||
if (isPentaPowerPrimeSeed.call(n)) ppps.add(n) |
|||
n = n + 1 |
|||
} |
|||
System.print("First thirty penta-power prime seeds:") |
|||
Fmt.tprint("$,9d", ppps, 10) |
|||
System.print("\nFirst penta-power prime seed greater than:") |
|||
n = 1 |
|||
var m = 1 |
|||
var c = 0 |
|||
while (true) { |
|||
if (isPentaPowerPrimeSeed.call(n)) { |
|||
c = c + 1 |
|||
if (n > m * 1e6) { |
|||
Fmt.print(" $2d million is the $r: $,10d", m, c, n) |
|||
m = m + 1 |
|||
if (m == 11) return |
|||
} |
|||
} |
|||
n = n + 1 |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
First thirty penta-power prime seeds: |
|||
1 5 69 1,665 2,129 25,739 29,631 62,321 77,685 80,535 |
|||
82,655 126,489 207,285 211,091 234,359 256,719 366,675 407,945 414,099 628,859 |
|||
644,399 770,531 781,109 782,781 923,405 1,121,189 1,158,975 1,483,691 1,490,475 1,512,321 |
|||
First penta-power prime seed greater than: |
|||
1 million is the 26th: 1,121,189 |
|||
2 million is the 39th: 2,066,079 |
|||
3 million is the 47th: 3,127,011 |
|||
4 million is the 51st: 4,059,525 |
|||
5 million is the 59th: 5,279,175 |
|||
6 million is the 63rd: 6,320,601 |
|||
7 million is the 68th: 7,291,361 |
|||
8 million is the 69th: 8,334,915 |
|||
9 million is the 71st: 9,100,671 |
|||
10 million is the 72nd: 10,347,035 |
|||
</pre> |
Revision as of 21:54, 19 August 2022
Generate the sequence of penta-power prime seeds: positive integers n such that:
n0 + n + 1, n1 + n + 1, n2 + n + 1, n3 + n + 1 and n4 + n + 1 are all prime.
- Task
- Find and display the first thirty penta-power prime seeds.
- Stretch
- Find and display the position and value of first with a value greater than ten million.
- See also
I can find no mention or record of this sequence anywhere. Perhaps I've invented it.
Raku
<lang perl6>use Lingua::EN::Numbers;
my @ppps = lazy (1..*).hyper(:2000batch).grep: -> \n { my \k = n + 1; (1+k).is-prime && (n+k).is-prime && (n²+k).is-prime && (n³+k).is-prime && (n⁴+k).is-prime }
say "First thirty penta-power prime seeds:\n" ~ @ppps[^30].batch(10)».&comma».fmt("%9s").join: "\n";
say "\nFirst penta-power prime seed greater than:";
for 1..10 {
my $threshold = Int(1e6 * $_); my $key = @ppps.first: * > $threshold, :k; say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@ppps[$key].&comma}";
}</lang>
- Output:
First thirty penta-power prime seeds: 1 5 69 1,665 2,129 25,739 29,631 62,321 77,685 80,535 82,655 126,489 207,285 211,091 234,359 256,719 366,675 407,945 414,099 628,859 644,399 770,531 781,109 782,781 923,405 1,121,189 1,158,975 1,483,691 1,490,475 1,512,321 First penta-power prime seed greater than: one million is the 26th: 1,121,189 two million is the 39th: 2,066,079 three million is the 47th: 3,127,011 four million is the 51st: 4,059,525 five million is the 59th: 5,279,175 six million is the 63rd: 6,320,601 seven million is the 68th: 7,291,361 eight million is the 69th: 8,334,915 nine million is the 71st: 9,100,671 ten million is the 72nd: 10,347,035
Wren
<lang ecmascript>import "./gmp" for Mpz import "./fmt" for Fmt
var p = Mpz.new() var q = Mpz.one
var isPentaPowerPrimeSeed = Fn.new { |n|
p.setUi(n) var k = n + 1 return (q + k).probPrime(15) > 0 && (p + k).probPrime(15) > 0 && (p.mul(n) + k).probPrime(15) > 0 && (p.mul(n) + k).probPrime(15) > 0 && (p.mul(n) + k).probPrime(15) > 0
}
var ppps = [] var n = 1 while (ppps.count < 30) {
if (isPentaPowerPrimeSeed.call(n)) ppps.add(n) n = n + 1
} System.print("First thirty penta-power prime seeds:") Fmt.tprint("$,9d", ppps, 10)
System.print("\nFirst penta-power prime seed greater than:") n = 1 var m = 1 var c = 0 while (true) {
if (isPentaPowerPrimeSeed.call(n)) { c = c + 1 if (n > m * 1e6) { Fmt.print(" $2d million is the $r: $,10d", m, c, n) m = m + 1 if (m == 11) return } } n = n + 1
}</lang>
- Output:
First thirty penta-power prime seeds: 1 5 69 1,665 2,129 25,739 29,631 62,321 77,685 80,535 82,655 126,489 207,285 211,091 234,359 256,719 366,675 407,945 414,099 628,859 644,399 770,531 781,109 782,781 923,405 1,121,189 1,158,975 1,483,691 1,490,475 1,512,321 First penta-power prime seed greater than: 1 million is the 26th: 1,121,189 2 million is the 39th: 2,066,079 3 million is the 47th: 3,127,011 4 million is the 51st: 4,059,525 5 million is the 59th: 5,279,175 6 million is the 63rd: 6,320,601 7 million is the 68th: 7,291,361 8 million is the 69th: 8,334,915 9 million is the 71st: 9,100,671 10 million is the 72nd: 10,347,035