Go Count Non Divisible
func countNonDivisible(a []int) []int {
size := len(a)
nonDivisors := make([]int, size)
maxVal := a[0]
for _, v := range a {
if v > maxVal {
maxVal = v
}
}
occurrences := make([]int, maxVal+1)
for _, v := range a {
occurrences[v]++
}
for k, v := range a {
count := 0
for i := 1; i*i <= v; i++ {
if v%i == 0 {
count += occurrences[i]
if v/i != i {
count += occurrences[v/i]
}
}
}
nonDivisors[k] = size - count
}
return nonDivisors
}
This counts how often each value appears, then subtracts the divisor matches so you get the non-divisible count for each item.