Jump to content

Ultra useful primes: Difference between revisions

Added Go
(Added Go)
Line 60:
<pre>
1 3 5 15 5 59 159 189 569 105
</pre>
 
=={{header|Go}}==
{{libheader|GMP(Go wrapper)}}
<lang go>package main
 
import (
"fmt"
big "github.com/ncw/gmp"
)
 
var two = big.NewInt(2)
 
func a(n uint) int {
one := big.NewInt(1)
p := new(big.Int).Lsh(one, 1 << n)
p.Sub(p, one)
for k := 1; ; k += 2 {
if p.ProbablyPrime(15) {
return k
}
p.Sub(p, two)
}
}
 
func main() {
fmt.Println(" n k")
fmt.Println("----------")
for n := uint(1); n < 14; n++ {
fmt.Printf("%2d %d\n", n, a(n))
}
}</lang>
 
{{out}}
<pre>
n k
----------
1 1
2 3
3 5
4 15
5 5
6 59
7 159
8 189
9 569
10 105
11 1557
12 2549
13 2439
</pre>
 
9,486

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.