package main
import (
"fmt"
"math"
)
func divi(div int) (int, int) {
var i int
for i = 2; i int(math.Sqrt(float64(div))); i++ {
if div%i == 0 {
return i, div / i
}
}
return 1, div
}
func main() {
var num, temp, buf int
fmt.Scanf("%d", &num)
fmt.Printf("%d = ", num)
buf = num
for temp != 1 {
temp, buf = divi(buf)
if buf == num {
fmt.Printf("%d * 1", num)
return
} else if temp == 1 {
fmt.Printf("%d", buf)
} else {
fmt.Printf("%d * ", temp)
}
}
}
运行结果:
90
90 = 2 * 3 * 3 * 5
...
2489
2489 = 19 * 131
...
45678
45678 = 2 * 3 * 23 * 331