Cullen and Woodall numbers: Difference between revisions

Added Go
(Cullen and Woodall numbers en Verilog)
(Added Go)
Line 261:
2 3 6 30 75 81 115 123 249 362 384 462
1 141 4713 5795 6611
</pre>
 
=={{header|Go}}==
{{libheader|GMP(Go wrapper)}}
<lang go>package main
 
import (
"fmt"
big "github.com/ncw/gmp"
)
 
func cullen(n uint) *big.Int {
one := big.NewInt(1)
bn := big.NewInt(int64(n))
res := new(big.Int).Lsh(one, n)
res.Mul(res, bn)
return res.Add(res, one)
}
 
func woodall(n uint) *big.Int {
res := cullen(n)
return res.Sub(res, big.NewInt(2))
}
 
func main() {
fmt.Println("First 20 Cullen numbers (n * 2^n + 1):")
for n := uint(1); n <= 20; n++ {
fmt.Printf("%d ", cullen(n))
}
 
fmt.Println("\n\nFirst 20 Woodall numbers (n * 2^n - 1):")
for n := uint(1); n <= 20; n++ {
fmt.Printf("%d ", woodall(n))
}
 
fmt.Println("\n\nFirst 5 Cullen primes (in terms of n):")
count := 0
for n := uint(1); count < 5; n++ {
cn := cullen(n)
if cn.ProbablyPrime(15) {
fmt.Printf("%d ", n)
count++
}
}
 
fmt.Println("\n\nFirst 12 Woodall primes (in terms of n):")
count = 0
for n := uint(1); count < 12; n++ {
cn := woodall(n)
if cn.ProbablyPrime(15) {
fmt.Printf("%d ", n)
count++
}
}
fmt.Println()
}</lang>
 
{{out}}
<pre>
First 20 Cullen numbers (n * 2^n + 1):
3 9 25 65 161 385 897 2049 4609 10241 22529 49153 106497 229377 491521 1048577 2228225 4718593 9961473 20971521
 
First 20 Woodall numbers (n * 2^n - 1):
1 7 23 63 159 383 895 2047 4607 10239 22527 49151 106495 229375 491519 1048575 2228223 4718591 9961471 20971519
 
First 5 Cullen primes (in terms of n):
1 141 4713 5795 6611
 
First 12 Woodall primes (in terms of n):
2 3 6 30 75 81 115 123 249 362 384 462
</pre>
 
9,482

edits