Penta-power prime seeds: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(Sigh)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(24 intermediate revisions by 17 users not shown)
Line 1:
{{draft task}}
 
Generate the sequence of penta-power prime seeds: positive integers '''n''' such that:
Line 29:
NB: The source of the ALGOL 68-primes library is on a Rosetta Code code page linked from the above.<br>
Note that to run this with ALGOL 68G under Windows (and probably Linux) a large heap size must be specified on the command line, e.g. <code>-heap 1024M</code>.
<langsyntaxhighlight lang="algol68">BEGIN # find some Penta power prime seeds, numbers n such that: #
# n^p + n + 1 is prime for p = 0. 1, 2, 3, 4 #
PR read "primes.incl.a68" PR # include prime utilities #
Line 104:
)
OD
END</langsyntaxhighlight>
{{out}}
<pre>
Line 123:
First element over 10000000: 10347035, index: 72
</pre>
 
=={{header|Arturo}}==
 
<syntaxhighlight lang="arturo">pentaPowerPrime?: function [n]->
every? [[n+2] [n+n+1] [1+n+n^2] [1+n+n^3] [1+n+n^4]] 'x ->
prime? do x
 
first30ppps: select.first:30 1..∞ => pentaPowerPrime?
 
loop split.every: 6 first30ppps 'x ->
print map x 's -> pad to :string s 7</syntaxhighlight>
 
{{out}}
 
<pre> 1 5 69 1665 2129 25739
29631 62321 77685 80535 82655 126489
207285 211091 234359 256719 366675 407945
414099 628859 644399 770531 781109 782781
923405 1121189 1158975 1483691 1490475 1512321</pre>
 
=={{header|C}}==
{{trans|Wren}}
{{libheader|GMP}}
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdbool.h>
#include <locale.h>
#include <gmp.h>
 
mpz_t p, p2, q;
 
bool isPentaPowerPrimeSeed(unsigned int n) {
int i;
mpz_set_ui(p, n);
unsigned int k = n + 1;
mpz_add_ui(p2, q, k);
if (!mpz_probab_prime_p(p2, 15)) return false;
mpz_add_ui(p2, p, k);
if (!mpz_probab_prime_p(p2, 15)) return false;
for (i = 0; i < 3; ++i) {
mpz_mul_ui(p, p, n);
mpz_set(p2, p);
mpz_add_ui(p2, p2, k);
if (!mpz_probab_prime_p(p2, 15)) return false;
}
return true;
}
 
const char *ord(int c) {
int m = c % 100;
if (m >= 4 && m <= 20) return "th";
m %= 10;
return (m == 1) ? "st" :
(m == 2) ? "nd" :
(m == 3) ? "rd" : "th";
}
 
int main() {
unsigned int n;
int c = 0, m = 1;
mpz_init(p);
mpz_init(p2);
mpz_init_set_ui(q, 1);
setlocale(LC_NUMERIC, "");
printf("First thirty penta-power prime seeds:\n");
for (n = 1; c < 30; n += 2) {
if (isPentaPowerPrimeSeed(n)) {
printf("%'9u ", n);
if (!((++c) % 10)) printf("\n");
}
}
 
n = 1;
c = 0;
printf("\nFirst penta-power prime seed greater than:\n");
while (1) {
if (isPentaPowerPrimeSeed(n)) {
++c;
if (n > 1000000 * m) {
printf(" %2d million is the %d%s: %'10u\n", m, c, ord(c), n);
if (++m == 11) break;
}
}
n += 2;
}
return 0;
}</syntaxhighlight>
 
{{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>
 
=={{header|F_Sharp|F#}}==
<syntaxhighlight lang="fsharp">
// Penta-power prime seeds. Nigel Galloway: April 5th., 2023
let fG n g=let n=bigint(n:int) in let n=n**g+n+1I in Open.Numeric.Primes.MillerRabin.IsProbablePrime &n
let fN(n,g)=Seq.initInfinite((+)n)|>Seq.filter(fun n->let g=fG n in g 0&&g 1&&g 2&&g 3&&g 4)|>Seq.mapi(fun n g->(n,g))|>Seq.find(snd>>(<)g)
Seq.initInfinite((*)2>>(+)1)|>Seq.filter(fun n->let g=fG n in g 0&&g 1&&g 2&&g 3&&g 4)|>Seq.take 30|>Seq.iter(printf "%d "); printfn "\n"
[1000000..1000000..10000000]|>Seq.scan(fun(n,g,x) l->let i,e=fN(g,l) in (n+i,e,l))(0,0,0)|>Seq.skip 1|>Seq.iter(fun(n,g,l)->printfn $"First element over %8d{l} is %9d{g} at index %3d{n}")
</syntaxhighlight>
{{out}}
<pre>
1 5 69 1665 2129 25739 29631 62321 77685 80535 82655 126489 207285 211091 234359 256719 366675 407945 414099 628859 644399 770531 781109 782781 923405 1121189 1158975 1483691 1490475 1512321
 
First element over 1000000 is 1121189 at index 25
First element over 2000000 is 2066079 at index 38
First element over 3000000 is 3127011 at index 46
First element over 4000000 is 4059525 at index 50
First element over 5000000 is 5279175 at index 58
First element over 6000000 is 6320601 at index 62
First element over 7000000 is 7291361 at index 67
First element over 8000000 is 8334915 at index 68
First element over 9000000 is 9100671 at index 70
First element over 10000000 is 10347035 at index 71
</pre>
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<syntaxhighlight lang="factor">USING: grouping io kernel lists lists.lazy math math.functions
math.primes prettyprint tools.memory.private ;
 
: seed? ( n -- ? )
5 [ dupd ^ 1 + + prime? ] with all-integers? ;
 
: pentas ( -- list )
1 lfrom [ seed? ] lfilter [ commas ] lmap-lazy ;
 
"First thirty penta-power prime seeds:" print
30 pentas ltake list>array 5 group simple-table.</syntaxhighlight>
{{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
</pre>
 
=={{header|FreeBASIC}}==
{{libheader|GMP}}
<syntaxhighlight lang="freebasic">' version 13-04-2023
' compile with: fbc -s console
 
#Include "gmp.bi"
#Define sieve_max 21000000
 
Dim As Mpz_ptr n2 = Allocate (Len(__mpz_struct))
Dim As Mpz_ptr n3 = Allocate (Len(__mpz_struct))
Dim As Mpz_ptr n4 = Allocate (Len(__mpz_struct))
Mpz_init(n2) : Mpz_init(n3) : Mpz_init(n4)
 
Dim As ULongInt i, j
ReDim As boolean sieve(sieve_max)
 
' default value on initialization is FALSE
sieve(2) = TRUE
' set all odd numbers to TRUE
For i = 3 To sieve_max Step 2
sieve(i) = TRUE
Next
For i = 3 To Sqr(sieve_max) Step 2
If sieve(i) = TRUE Then
For j = i * i To sieve_max Step i * 2
sieve(j) = FALSE
Next
End If
Next
 
Dim As LongInt n = -1, count, k
Dim As LongInt si = 15
 
Print "The first thirty penta-power prime seeds are:"
While count < 30
n += 2
k = n +1
' n ^ 0 = 1
If sieve(1 + k) And sieve(n + k) Then ' skip if 1 + k or n + k is not prime
Mpz_ui_pow_ui(n4, n , 4)
Mpz_add_ui(n4, n4, k)
If Mpz_probab_prime_p(n4, si) < 1 Then Continue While ' skip if not prime
Mpz_ui_pow_ui(n3, n, 3)
Mpz_add_ui(n3, n3, k)
If Mpz_probab_prime_p(n3, si) < 1 Then Continue While ' skip if not prime
Mpz_ui_pow_ui(n2, n, 2)
Mpz_add_ui(n2, n2, k)
If Mpz_probab_prime_p(n2, si) >= 1 Then ' if prime then print n
Print Using "##########"; n;
count += 1
If (count Mod 10) = 0 Then Print
End If
End If
Wend
 
Dim As ULongInt m = 1, million = 1000000
n = -1 : count = 0
Print !"\n\nFirst penta-power prime seed greater than:"
While m < 11
n += 2
k = n +1
If sieve(1 + k) And sieve(n + k) Then ' skip if 1 + k or n + k is not prime
Mpz_ui_pow_ui(n4, n , 4)
Mpz_add_ui(n4, n4, k)
If Mpz_probab_prime_p(n4, si) < 1 Then Continue While ' skip if not prime
Mpz_ui_pow_ui(n3, n, 3)
Mpz_add_ui(n3, n3, k)
If Mpz_probab_prime_p(n3, si) < 1 Then Continue While ' skip if not prime
Mpz_ui_pow_ui(n2, n, 2)
Mpz_add_ui(n2, n2, k)
If Mpz_probab_prime_p(n2, si) >= 1 Then
count += 1
If n > million Then
Print Using " ## million is #########, at index ### "; m; n; count
m += 1
million = m * 1000000
End If
End If
End If
Wend
 
Mpz_clear(n4) : Mpz_clear(n3) : Mpz_clear(n2)
 
 
' empty keyboard buffer
While InKey <> "" : Wend
Print : Print "hit any key to end program"
Sleep
End</syntaxhighlight>
{{out}}
<pre>The first thirty penta-power prime seeds are:
1 5 69 1665 2129 25739 29631 62321 77685 80535
82655 126489 207285 211091 234359 256719 366675 407945 414099 628859
644399 770531 781109 782781 923405 1121189 1158975 1483691 1490475 1512321
 
 
First penta-power prime seed greater than:
1 million is 1,121,189 at index 26
2 million is 2,066,079 at index 39
3 million is 3,127,011 at index 47
4 million is 4,059,525 at index 51
5 million is 5,279,175 at index 59
6 million is 6,320,601 at index 63
7 million is 7,291,361 at index 68
8 million is 8,334,915 at index 69
9 million is 9,100,671 at index 71
10 million is 10,347,035 at index 72</pre>
 
=={{header|Go}}==
{{trans|Wren}}
{{libheader|GMP(Go wrapper)}}
{{libheader|Go-rcu}}
<syntaxhighlight lang="go">package main
 
import (
"fmt"
big "github.com/ncw/gmp"
"rcu"
)
 
var p, p2, q *big.Int
 
func isPentaPowerPrimeSeed(n uint64) bool {
nn := new(big.Int).SetUint64(n)
p.Set(nn)
k := new(big.Int).SetUint64(n + 1)
p2.Add(q, k)
if !p2.ProbablyPrime(15) {
return false
}
p2.Add(p, k)
if !p2.ProbablyPrime(15) {
return false
}
for i := 0; i < 3; i++ {
p.Mul(p, nn)
p2.Set(p)
p2.Add(p2, k)
if !p2.ProbablyPrime(15) {
return false
}
}
return true
}
 
func ord(c int) string {
m := c % 100
if m > 4 && m <= 20 {
return "th"
}
m %= 10
switch m {
case 1:
return "st"
case 2:
return "nd"
case 3:
return "rd"
default:
return "th"
}
}
 
func main() {
p = new(big.Int)
p2 = new(big.Int)
q = big.NewInt(1)
c := 0
m := 1
n := uint64(1)
fmt.Println("First thirty penta-power prime seeds:")
for ; c < 30; n += 2 {
if isPentaPowerPrimeSeed(n) {
fmt.Printf("%9s ", rcu.Commatize(int(n)))
c++
if c%10 == 0 {
fmt.Println()
}
}
}
 
n = 1
c = 0
fmt.Println("\nFirst penta-power prime seed greater than:")
for {
if isPentaPowerPrimeSeed(n) {
c++
if n > 1000000*uint64(m) {
ns := rcu.Commatize(int(n))
fmt.Printf(" %2d million is the %d%s: %10s\n", m, c, ord(c), ns)
m++
if m == 11 {
break
}
}
}
n += 2
}
}</syntaxhighlight>
 
{{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>
 
=={{header|J}}==
<syntaxhighlight lang=j> ps=. ] #~ 1 p: 1 + ^~ + ]
 
_10 ]\ 4x ps 3x ps 2 ps 1 ps 0 ps i. 1520000
1 5 69 1665 2129 25739 29631 62321 77685 80535
82655 126489 207285 211091 234359 256719 366675 407945 414099 628859
644399 770531 781109 782781 923405 1121189 1158975 1483691 1490475 1512321</syntaxhighlight>
 
=={{header|Java}}==
<syntaxhighlight lang="java">
import java.math.BigInteger;
 
public final class PentaPowerPrimeSeeds {
 
public static void main(String[] args) {
System.out.println("The first 30 penta-power prime seeds:");
int index = 0;
int number = 1;
boolean searching = true;
while ( searching ) {
if ( isPentaPowerPrimeSeed(number) ) {
index += 1;
if ( index <= 30 ) {
System.out.print(String.format("%7d%s", number, ( index % 6 == 0 ? "\n" : " " )));
} else if ( number > 10_000_000 ) {
System.out.println();
System.out.println("The first penta-power prime seed greater than 10,000,000 is "
+ number + " at index " + index);
searching = false;
}
}
number += 2;
}
}
private static boolean isPentaPowerPrimeSeed(long number) {
BigInteger p = BigInteger.ONE;
BigInteger nPlus1 = BigInteger.valueOf(number + 1);
for ( int i = 0; i <= 4; i++ ) {
if ( ! p.add(nPlus1).isProbablePrime(15) ) {
return false;
}
p = p.multiply(BigInteger.valueOf(number));
}
return true;
}
 
}
</syntaxhighlight>
{{ out }}
<pre>
The first 30 penta-power prime seeds:
1 5 69 1665 2129 25739
29631 62321 77685 80535 82655 126489
207285 211091 234359 256719 366675 407945
414099 628859 644399 770531 781109 782781
923405 1121189 1158975 1483691 1490475 1512321
 
The first penta-power prime seed greater than 10,000,000 is 10347035 at index 72
</pre>
 
=={{header|Julia}}==
 
This solution uses Primes to determine primality.
 
<syntaxhighlight lang=julia>
using Primes, Printf
 
function ispenta(n)
all(0:4) do i
isprime(n^i + n + 1)
end
end
 
function firstpenta(m, T=BigInt)
nums = Iterators.countfrom(T(1))
pentas = Iterators.filter(ispenta, nums)
firstn = Iterators.take(pentas, m)
return collect(firstn)
end
 
function table_display(nums, num_columns)
num_elements = length(nums)
num_rows = div(num_elements, num_columns)
remaining_elements = num_elements % num_columns
 
for i in 1:num_rows
for j in 1:num_columns
index = (i - 1) * num_columns + j
print(nums[index], "\t")
end
println()
end
 
for i in 1:remaining_elements
index = num_rows * num_columns + i
print(nums[index], "\t")
end
println()
end
 
function stretch_penta(goal, T=BigInt)
nums = Iterators.countfrom(T(1))
pentas = Iterators.filter(ispenta, nums)
firstn = Iterators.takewhile(<=(goal), pentas)
return collect(firstn)
end
 
function run_rosetta()
fp = firstpenta(30)
println("First 30 Penta power prime seeds:")
table_display(fp, 10)
sp = stretch_penta(20000000)
milestones = 1000000 .* (1:10)
for milestone in milestones
index = findfirst(>(milestone), sp)
@printf "First element over %9i: %9i, index:%4i\n" milestone sp[index] index
end
end
 
if abspath(PROGRAM_FILE) == @__FILE__
run_rosetta()
end
</syntaxhighlight>
 
<pre>
First 30 Penta power prime seeds:
1 5 69 1665 2129 25739 29631 62321 77685 80535
82655 126489 207285 211091 234359 256719 366675 407945 414099 628859
644399 770531 781109 782781 923405 1121189 1158975 1483691 1490475 1512321
 
First element over 1000000: 1121189, index: 26
First element over 2000000: 2066079, index: 39
First element over 3000000: 3127011, index: 47
First element over 4000000: 4059525, index: 51
First element over 5000000: 5279175, index: 59
First element over 6000000: 6320601, index: 63
First element over 7000000: 7291361, index: 68
First element over 8000000: 8334915, index: 69
First element over 9000000: 9100671, index: 71
First element over 10000000: 10347035, index: 72
</pre>
 
=={{header|jq}}==
The specified tasks are beyond the capabilties of the current
implementations of jq:
 
* The C implementation (jq) does not support unbounded-precision integer arithmetic, and so is in effect only capable of generating the first few penta-power prime (ppp) seeds.
 
* The Go implementation (gojq) does support unbounded-precision integer arithmetic and the following program has been used to generate the first 13 ppp seeds, but gojq takes a long while to do so; other variants of the program have been considered but they run into gojq's memory-management limitations.
 
The program given below may nevertheless be of some interest as it
illustrates how a JSON dictionary can be used to cache the primes up
to a certain limit, and how this can be done using a sieve
economically:
<syntaxhighlight lang=jq>
# Create a dictionary for the primes up to .
def primeDictionary:
# The array we use for the sieve only stores information for the odd integers greater than 1:
# index integer
# 0 3
# k 2*k + 3
# So if we wish to mark m = 2*k + 3, the relevant index is: m - 3 / 2
def ix:
if . % 2 == 0 then null
else ((. - 3) / 2)
end;
# erase(i) sets .[i*j] to false for odd integral j > i, and assumes i is odd
def erase(i):
((i - 3) / 2) as $k
# Consider relevant multiples:
| (((length * 2 + 3) / i)) as $upper
# ... only consider odd multiples from i onwards
| reduce range(i; $upper; 2) as $j (.;
(((i * $j) - 3) / 2) as $m
| if .[$m] then .[$m] = false else . end);
 
if . < 2 then {}
else (. + 1) as $n
| (($n|sqrt) / 2) as $s
| [range(3; $n; 2)|true]
| reduce (1 + (2 * range(1; $s)) ) as $i (.; erase($i))
| . as $sieve
| reduce (2, (range(3; $n; 2) | select($sieve[ix]))) as $i ({}; .[$i|tostring]=$i)
end ;
</syntaxhighlight>
 
 
<syntaxhighlight lang=jq>
# Input should be an integer
def isPrime:
. as $n
| if ($n < 2) then false
elif ($n % 2 == 0) then $n == 2
elif ($n % 3 == 0) then $n == 3
else 5
| until( . <= 0;
if .*. > $n then -1
elif ($n % . == 0) then 0
else . + 2
| if ($n % . == 0) then 0
else . + 4
end
end)
| . == -1
end;
 
# $primedictionary should be a dictionary of primes up to $small
def ispentapowerprime($primedictionary; $small):
 
def isp: if . <= $small then $primedictionary[tostring] else isPrime end;
 
. as $n
| (. * .) as $n2
| (. * $n2) as $n3
| all($n + 2, $n + $n + 1, $n2 + $n + 1, $n3 + $n + 1, $n3 * $n + $n + 1; isp);
 
# Output: a stream of the first $count penta-power prime-seeds
# The size of the dictionary has been chosen with gojq in mind.
def ppprimes($count):
# The size of primeDictionary has been chosen with gojq's limitations in mind
($count | .*.*. | primeDictionary) as $pd
 
| limit($count; 1, 2, range(3; infinite; 2) | select(ispentapowerprime($pd; $small)) );
 
ppprimes(30)
</syntaxhighlight>
{{output}}
Using gojq, progress effectively grinds to a halt after 207285.
<pre>
1
5
69
1665
2129
25739
29631
62321
77685
80535
82655
126489
207285
<terminated>
</pre>
 
=={{header|Nim}}==
{{libheader|Nim-Integers}}
<syntaxhighlight lang=Nim>import std/[strformat, strutils]
import integers
 
func isPentaPowerPrimeSeeds(n: Integer): bool =
var p = newInteger(1)
var n1 = n + 1
for _ in 0..4:
if not isPrime(p + n1): return false
p *= n
result = true
 
const N = 10_000_000
 
echo "First 30 penta-power prime seeds:"
var count = 0
var n = 1
while true:
if n.isPentaPowerPrimeSeeds():
inc count
if count <= 30:
stdout.write &"{n:7}"
stdout.write if count mod 6 == 0: '\n' else: ' '
if count == 30: echo()
elif n > N:
echo &"First penta-power prime seed greater than {insertSep($N)} " &
&"is {insertSep($n)} at position {count}."
break
inc n, 2
</syntaxhighlight>
 
{{out}}
<pre>First 30 penta-power prime seeds:
1 5 69 1665 2129 25739
29631 62321 77685 80535 82655 126489
207285 211091 234359 256719 366675 407945
414099 628859 644399 770531 781109 782781
923405 1121189 1158975 1483691 1490475 1512321
 
First penta-power prime seed greater than 10_000_000 is 10_347_035 at position 72.
</pre>
 
=={{header|Perl}}==
{{libheader|ntheory}}
<syntaxhighlight lang="perl" line>use v5.36;
use bigint;
use ntheory 'is_prime';
use List::Util 'max';
 
sub comma { reverse ((reverse shift) =~ s/(.{3})/$1,/gr) =~ s/^,//r }
sub table ($c, @V) { my $t = $c * (my $w = 2 + max map {length} @V); ( sprintf( ('%'.$w.'s')x@V, @V) ) =~ s/.{1,$t}\K/\n/gr }
 
my($i,@ppps);
while (@ppps < 30) {
my $k = 1 + (my $n = 2 * $i++ + 1);
push @ppps, comma $n if
is_prime( 1 + $k) and
is_prime($n + $k) and
is_prime($n**2 + $k) and
is_prime($n**3 + $k) and
is_prime($n**4 + $k);
}
 
say 'First thirty penta-power prime seeds:';
say table(10,@ppps);</syntaxhighlight>
{{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</pre>
 
=={{header|Phix}}==
<!--<langsyntaxhighlight Phixlang="phix">(phixonline)-->
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">include</span> <span style="color: #004080;">mpfr</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
Line 164 ⟶ 857:
<span style="color: #008080;">end</span> <span style="color: #008080;">while</span>
<span style="color: #7060A8;">printf</span><span style="color: #0000FF;">(</span><span style="color: #000000;">1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"First penta-power prime seed greater than:\n%s"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">l</span><span style="color: #0000FF;">)</span>
<!--</langsyntaxhighlight>-->
{{out}}
<pre>
Line 183 ⟶ 876:
nine million is 9,100,671 (the seventy-first)
ten million is 10,347,035 (the seventy-second)
</pre>
 
=={{header|Python}}==
<syntaxhighlight lang=python>from sympy import isprime
 
def ispentapowerprime(n):
return all(isprime(i) for i in [n + 2, n + n + 1, n**2 + n + 1, n**3 + n + 1, n**4 + n + 1])
 
ppprimes = [i for i in range(10_400_000) if ispentapowerprime(i)]
 
for i in range(50):
print(f'{ppprimes[i]: 11,}', end='\n' if (i + 1) % 10 == 0 else '')
 
for n in range(1_000_000, 10_000_001, 1_000_000):
proot = next(filter(lambda x: x > n, ppprimes))
print(f'The first penta-power prime seed over {n:,} is {proot:,}')
</syntaxhighlight>{{out}}
<pre>
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
1,711,991 1,716,989 1,780,485 1,791,041 1,835,589 1,860,011 1,861,259 1,980,441 2,066,079 2,211,705
2,215,529 2,271,009 2,413,265 2,514,161 2,915,109 2,940,405 3,127,011 3,587,319 3,890,769 3,992,379
The first penta-power prime seed over 1,000,000 is 1,121,189
The first penta-power prime seed over 2,000,000 is 2,066,079
The first penta-power prime seed over 3,000,000 is 3,127,011
The first penta-power prime seed over 4,000,000 is 4,059,525
The first penta-power prime seed over 5,000,000 is 5,279,175
The first penta-power prime seed over 6,000,000 is 6,320,601
The first penta-power prime seed over 7,000,000 is 7,291,361
The first penta-power prime seed over 8,000,000 is 8,334,915
The first penta-power prime seed over 9,000,000 is 9,100,671
The first penta-power prime seed over 10,000,000 is 10,347,035
</pre>
 
=={{header|Raku}}==
<syntaxhighlight lang="raku" perl6line>use Lingua::EN::Numbers;
 
my @ppps = lazy (^∞).hyper(:5000batch).map(* × 2 + 1).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 }
Line 198 ⟶ 924:
my $key = @ppps.first: * > $threshold, :k;
say "{$threshold.&cardinal.fmt: '%13s'} is the {ordinal-digit $key + 1}: {@ppps[$key].&comma}";
}</langsyntaxhighlight>
{{out}}
<pre>First thirty penta-power prime seeds:
Line 216 ⟶ 942:
nine million is the 71st: 9,100,671
ten million is the 72nd: 10,347,035</pre>
 
=={{header|RPL}}==
Directly adapted from [[Quad-power prime seeds#RPL|Quad-power prime seeds]], but faster since seeds must be odd to get <code>n<sup>0</sup> + n + 1</code> primality. However, needs to be run on an emulator to get the result in around half an hour.
{{works with|HP|49}}
« { } 1
'''WHILE''' OVER SIZE 30 < '''REPEAT'''
1 SF
0 4 '''FOR''' j
DUP j ^ OVER + 1 +
'''IF''' ISPRIME? NOT '''THEN''' 1 CF 4 'j' STO '''END'''
'''NEXT'''
'''IF''' 1 FS? '''THEN''' SWAP OVER + SWAP '''END '''
2 +
'''END'''
» '<span style="color:blue">TASK</span>' STO
{{out}}
<pre>
1:{1 5 69 1665 2129 25739 29631 62321 77685 80535 82655 126489 207285 211091 234359 256719 366675 407945 414099 628859 644399 770531 781109 782781 923405 1121189 1158975 1483691 1490475 1512321}
</pre>
 
=={{header|Ruby}}==
<syntaxhighlight lang="ruby">require 'openssl'
 
pent_pow_primes = (1..).lazy.select{|n| (0..4).all?{|exp| OpenSSL::BN.new(n**exp + n + 1).prime?} }
 
n = 30
puts "The first #{n} penta-power prime seeds:"
pent_pow_primes.take(n).each_slice(10){|s| puts "%8s"*s.size % s}</syntaxhighlight>
{{out}}
<pre>The first 30 penta-power prime seeds:
1 5 69 1665 2129 25739 29631 62321 77685 80535
82655 126489 207285 211091 234359 256719 366675 407945 414099 628859
644399 770531 781109 782781 923405 1121189 1158975 1483691 1490475 1512321
</pre>
 
=={{header|Scala}}==
{{trans|Java}}
<syntaxhighlight lang="Scala">
import scala.annotation.tailrec
import java.math.BigInteger
 
object PentaPowerPrimeSeeds extends App {
println("The first 30 penta-power prime seeds:")
val first30 = Stream.from(1, 2).filter(isPentaPowerPrimeSeed).take(30)
first30.zipWithIndex.foreach { case (seed, index) =>
print(f"$seed%7d${if ((index + 1) % 6 == 0) "\n" else " "}")
}
 
val firstAbove10M = Stream.from(1, 2).filter(isPentaPowerPrimeSeed).find(_ > 10000000)
firstAbove10M match {
case Some(seed) => println(s"\nThe first penta-power prime seed greater than 10,000,000 is $seed")
case None => println("No penta-power prime seed greater than 10,000,000 was found.")
}
 
def isPentaPowerPrimeSeed(number: Int): Boolean = {
val bigIntNumber = BigInteger.valueOf(number)
val bigIntNumberPlusOne = bigIntNumber.add(BigInteger.ONE)
(0 to 4).forall { i =>
bigIntNumber.pow(i).add(bigIntNumberPlusOne).isProbablePrime(15)
}
}
}
</syntaxhighlight>
{{out}}
<pre>
The first 30 penta-power prime seeds:
1 5 69 1665 2129 25739
29631 62321 77685 80535 82655 126489
207285 211091 234359 256719 366675 407945
414099 628859 644399 770531 781109 782781
923405 1121189 1158975 1483691 1490475 1512321
 
The first penta-power prime seed greater than 10,000,000 is 10347035
 
</pre>
 
 
 
=={{header|Wren}}==
{{libheader|Wren-gmp}}
{{libheader|Wren-fmt}}
<langsyntaxhighlight ecmascriptlang="wren">import "./gmp" for Mpz
import "./fmt" for Fmt
 
Line 259 ⟶ 1,062:
}
n = n + 2
}</langsyntaxhighlight>
 
{{out}}
9,476

edits