Skip to content

Instantly share code, notes, and snippets.

@sguzman
Created May 11, 2015 08:06
Show Gist options
  • Save sguzman/fcf8b9362258f2f13c0f to your computer and use it in GitHub Desktop.
Save sguzman/fcf8b9362258f2f13c0f to your computer and use it in GitHub Desktop.
factor 27^140... of course, its only prime factor is 3
package main
import (
"fmt"
"math/big"
//util "github.com/cznic/mathutil"
)
func Copy(from *big.Int) (*big.Int) {
stubby := big.NewInt(1)
stubby.SetString(from.String(), 10)
return stubby
}
func main() {
factors := make(map[uint64]uint64)
index := big.NewInt(4)
index.Exp(big.NewInt(27), big.NewInt(140), nil)
//limit := util.SqrtBig(index)
div := big.NewInt(1)
mod := big.NewInt(1)
zero := big.NewInt(0)
one := big.NewInt(1)
for i := big.NewInt(2); i.Cmp(big.NewInt(100)) < 0; {
div.DivMod(index, i, mod)
fmt.Println("index: ", index, ", i: ", i)
fmt.Println("mod: ", mod)
if mod.Cmp(zero) == 0 {
factors[i.Uint64()] += 1
index.SetString(div.String(), 10)
i = big.NewInt(2)
} else {
i.Add(i, one)
}
}
fmt.Println(factors)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment