PHP Count Non Divisible
function countNonDivisible(array $a): array
{
    $size       = count($a);
    $nondivisor = array_fill(0, $size, 0);
    $occurences = array_fill(0, max($a) + 1, 0);

    foreach ($a as $v) {
        $occurences[$v]++;
    }

    foreach ($a as $k => $v) {
        $count = 0;
        $i     = 1;
        while ($i * $i <= $v) {
            if ($v % $i === 0) {
                $count += $occurences[$i];
                if ($v / $i !== $i) {
                    $count += $occurences[$v / $i];
                }
            }
            $i++;
        }
        $nondivisor[$k] = $size - $count;
    }

    return $nondivisor;
}

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