brute-force solution to the CountNonDivisible problem