Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Prime-decomposition/Go/prime-decomposition.go
Normal file
39
Task/Prime-decomposition/Go/prime-decomposition.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var (
|
||||
ZERO = big.NewInt(0)
|
||||
ONE = big.NewInt(1)
|
||||
)
|
||||
|
||||
func Primes(n *big.Int) []*big.Int {
|
||||
res := []*big.Int{}
|
||||
mod, div := new(big.Int), new(big.Int)
|
||||
for i := big.NewInt(2); i.Cmp(n) != 1; {
|
||||
div.DivMod(n, i, mod)
|
||||
for mod.Cmp(ZERO) == 0 {
|
||||
res = append(res, new(big.Int).Set(i))
|
||||
n.Set(div)
|
||||
div.DivMod(n, i, mod)
|
||||
}
|
||||
i.Add(i, ONE)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func main() {
|
||||
vals := []int64{
|
||||
1 << 31,
|
||||
1234567,
|
||||
333333,
|
||||
987653,
|
||||
2 * 3 * 5 * 7 * 11 * 13 * 17,
|
||||
}
|
||||
for _, v := range vals {
|
||||
fmt.Println(v, "->", Primes(big.NewInt(v)))
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue