题解 | #质数因子#
质数因子
http://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
package main
import(
"strconv"
"fmt"
"strings"
)
func main(){
//如果N有质因子,那它绝不可能比根号n还要大
var num int
fmt.Scanln(&num)
res := make([]string,0)
i:=2
for num >= i * i{
for num % i == 0{
num = num / i
res = append(res, strconv.Itoa(i))
}
i++
}
if num > 1{
res = append(res, strconv.Itoa(num))
}
fmt.Println(strings.Join(res," "))
}
import(
"strconv"
"fmt"
"strings"
)
func main(){
//如果N有质因子,那它绝不可能比根号n还要大
var num int
fmt.Scanln(&num)
res := make([]string,0)
i:=2
for num >= i * i{
for num % i == 0{
num = num / i
res = append(res, strconv.Itoa(i))
}
i++
}
if num > 1{
res = append(res, strconv.Itoa(num))
}
fmt.Println(strings.Join(res," "))
}