Quad-power prime seeds: Difference between revisions

From Rosetta Code
Content added Content deleted
(→‎{{header|Wren}}: Added 10 million for consistency with 'penta' task.)
Line 60: Line 60:
p.setUi(n)
p.setUi(n)
var k = n + 1
var k = n + 1
return (p + k).probPrime(15) > 0 &&
return (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 &&
(p.mul(n) + k).probPrime(15) > 0 &&
Line 82: Line 82:
c = c + 1
c = c + 1
if (n > m * 1e6) {
if (n > m * 1e6) {
Fmt.print(" $d million is the $r: $,d", m, c, n)
Fmt.print(" $2d million is the $r: $,10d", m, c, n)
m = m + 1
m = m + 1
if (m == 10) return
if (m == 11) return
}
}
}
}
Line 100: Line 100:


First quad-power prime seed greater than:
First quad-power prime seed greater than:
1 million is the 141st: 1,009,286
1 million is the 141st: 1,009,286
2 million is the 234th: 2,015,496
2 million is the 234th: 2,015,496
3 million is the 319th: 3,005,316
3 million is the 319th: 3,005,316
4 million is the 383rd: 4,004,726
4 million is the 383rd: 4,004,726
5 million is the 452nd: 5,023,880
5 million is the 452nd: 5,023,880
6 million is the 514th: 6,000,554
6 million is the 514th: 6,000,554
7 million is the 567th: 7,047,129
7 million is the 567th: 7,047,129
8 million is the 601st: 8,005,710
8 million is the 601st: 8,005,710
9 million is the 645th: 9,055,151
9 million is the 645th: 9,055,151
10 million is the 701st: 10,023,600
</pre>
</pre>

Revision as of 22:00, 19 August 2022

Quad-power prime seeds is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Generate the sequence of quad-power prime seeds: positive integers n such that:

   n1 + n + 1, n2 + n + 1, n3 + n + 1 and n4 + n + 1 are all prime.


Task
  • Find and display the first fifty quad-power prime seeds.


Stretch
  • Find and display the position and value of first with a value greater than one million, two million, three million.


See also



Raku

<lang perl6>use Lingua::EN::Numbers;

my @qpps = lazy (1..*).hyper(:2000batch).grep: -> \n { my \k = n + 1; (n+k).is-prime && (n²+k).is-prime && (n³+k).is-prime && (n⁴+k).is-prime }

say "First fifty quad-power prime seeds:\n" ~ @qpps[^50].batch(10)».&comma».fmt("%7s").join: "\n";

say "\nFirst quad-power prime seed greater than:";

for 1..5 {

   my $threshold = Int(1e6 * $_);
   my $key = @qpps.first: * > $threshold, :k;
   say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@qpps[$key].&comma}";

}</lang>

Output:
First fifty quad-power prime seeds:
      1       2       5       6      69     131     426   1,665   2,129   2,696
  5,250   7,929   9,689  13,545  14,154  14,286  16,434  19,760  25,739  27,809
 29,631  36,821  41,819  46,619  48,321  59,030  60,500  61,955  62,321  73,610
 77,685  79,646  80,535  82,655  85,251  86,996  91,014  96,566  97,739 105,939
108,240 108,681 119,754 122,436 123,164 126,489 140,636 150,480 153,179 163,070

First quad-power prime seed greater than:
  one million is the 141st: 1,009,286
  two million is the 234th: 2,015,496
three million is the 319th: 3,005,316
 four million is the 383rd: 4,004,726
 five million is the 452nd: 5,023,880

Wren

Library: Wren-gmp
Library: Wren-fmt

GMP allows us to stretch a little more. <lang ecmascript>import "./gmp" for Mpz import "./fmt" for Fmt

var p = Mpz.new()

var isQuadPowerPrimeSeed = Fn.new { |n|

   p.setUi(n)
   var k = n + 1
   return (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 qpps = [] var n = 1 while (qpps.count < 50) {

   if (isQuadPowerPrimeSeed.call(n)) qpps.add(n)
   n = n + 1

} System.print("First fifty quad-power prime seeds:") Fmt.tprint("$,7d", qpps, 10)

System.print("\nFirst quad-power prime seed greater than:") var m = 1 var c = 50 while (true) {

   if (isQuadPowerPrimeSeed.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 fifty quad-power prime seeds:
      1       2       5       6      69     131     426   1,665   2,129   2,696 
  5,250   7,929   9,689  13,545  14,154  14,286  16,434  19,760  25,739  27,809 
 29,631  36,821  41,819  46,619  48,321  59,030  60,500  61,955  62,321  73,610 
 77,685  79,646  80,535  82,655  85,251  86,996  91,014  96,566  97,739 105,939 
108,240 108,681 119,754 122,436 123,164 126,489 140,636 150,480 153,179 163,070 

First quad-power prime seed greater than:
  1 million is the 141st:  1,009,286
  2 million is the 234th:  2,015,496
  3 million is the 319th:  3,005,316
  4 million is the 383rd:  4,004,726
  5 million is the 452nd:  5,023,880
  6 million is the 514th:  6,000,554
  7 million is the 567th:  7,047,129
  8 million is the 601st:  8,005,710
  9 million is the 645th:  9,055,151
 10 million is the 701st: 10,023,600