Haskell Count Non Divisible
import qualified Data.Map.Strict as Map

countNonDivisible :: [Int] -> [Int]
countNonDivisible a = map (\v -> size - divisorCount v) a
  where
    size = length a
    occ  = Map.fromListWith (+) [(v, 1 :: Int) | v <- a]
    occCount v = Map.findWithDefault 0 v occ

    divisorCount v =
      sum
        [ occCount i + (if v `div` i /= i then occCount (v `div` i) else 0)
        | i <- takeWhile (\i -> i * i <= v) [1 ..]
        , v `mod` i == 0
        ]

This counts how often each value appears, then subtracts the divisor matches so you get the non-divisible count for each item.