You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
lavos/cap3/work10.go

34 lines
626 B

package cap3
// Work10 狼找兔子,返回兔子是否有幸免的机会,有则返回可能的洞穴
func Work10(m, n int) (bool, []int) {
gcd := func(m, n int) int {
a, b := m, n
if m < n {
a, b = n, m
}
r := a % b
for r != 0 {
a = b
b = r
r = a % b
}
return b
}
r := gcd(m, n)
if r == 1 {
return false, nil
}
safeHoles := make([]int, 0)
for i := 0; i < n; i++ {
if i%r != 0 {
safeHoles = append(safeHoles, i)
}
}
return true, safeHoles
}