TypeScript Count Non Divisible
function countNonDivisible(a: number[]): number[] {
  const size = a.length;
  const nondivisor: number[] = new Array(size).fill(0);
  const occurences: number[] = new Array(Math.max(...a) + 1).fill(0);

  for (const v of a) {
    occurences[v]++;
  }

  for (let k = 0; k < size; k++) {
    const v = a[k];
    let count = 0;
    let 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.