Penta-power prime seeds: Difference between revisions
Content added Content deleted
(→{{header|C}}: fifty -> thirty) |
(Added Go) |
||
Line 252: | Line 252: | ||
644,399 770,531 781,109 782,781 923,405 |
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,121,189 1,158,975 1,483,691 1,490,475 1,512,321 |
||
</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> |
</pre> |
||
Line 357: | Line 469: | ||
<terminated> |
<terminated> |
||
</pre> |
</pre> |
||
=={{header|Perl}}== |
=={{header|Perl}}== |