AcWing 869. 试除法求约数-golang
原题链接
简单
作者:
一只鱼
,
2021-03-18 11:41:14
,
所有人可见
,
阅读 242
试除法求约数-golang
试除法求约数-golang
package main
import (
"fmt"
"sort"
)
var n int
func main(){
fmt.Scanf("%d", &n)
var num int
for i := 0; i < n; i++{
fmt.Scanf("%d", &num)
isDivid(num)
}
}
func isDivid(x int){
res := make([]int, 0, n)
for i := 1; i <= x/i; i++{
if x%i == 0{
res = append(res, i)
if x/i != i{
res = append(res, x/i)
}
}
}
sort.Slice(res, func(i, j int) bool {
return res[i] < res[j]
})
for i := 0; i < len(res); i++{
fmt.Printf("%d ", res[i])
}
fmt.Println()
}