Skip to content

Instantly share code, notes, and snippets.

@attilaolah
Created March 12, 2014 07:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save attilaolah/9502615 to your computer and use it in GitHub Desktop.
Save attilaolah/9502615 to your computer and use it in GitHub Desktop.
Naive take on this math problem: http://math.stackexchange.com/q/597234
package main
import (
"math/big"
"fmt"
)
type powersOf struct {
E int64
b, n *big.Int
}
func newPowersOf(n int64) *powersOf {
return &powersOf{
b: big.NewInt(1),
n: big.NewInt(n),
}
}
func (p *powersOf) Next() *big.Int {
p.E++
p.b = p.b.Mul(p.b, p.n)
return p.b
}
func main() {
var x *big.Int
p := newPowersOf(38)
q := big.NewInt(31)
for {
x = p.Next()
// http://math.stackexchange.com/q/597234#comment1258402_597234
if (p.E%12 != 0) && (p.E%12 != 8) {
continue
}
// http://math.stackexchange.com/q/597234#comment1447435_597234
if p.E < 185000 {
continue
}
fmt.Printf("\rn=%d, bitlen=%d", p.E, x.BitLen())
if x.Add(x, q).ProbablyPrime(8) {
fmt.Printf("\nPRIME(8) for n=%d\n", p.E)
break
}
x.Sub(x, q)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment