Created
July 11, 2018 18:05
-
-
Save yosoul93/c93749c495fd98b7caffc3368fe033c4 to your computer and use it in GitHub Desktop.
Count Non Divisor, it took me 35 minutes to solve it and this task is medium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function solution(A) { | |
var len = A.length, | |
count = [], | |
i, | |
k, | |
divisors = [], | |
result = []; | |
for (i = 0; i < 2 * len + 1; ++i){ | |
count.push(0); | |
divisors.push(0); | |
} | |
for (i = 0; i < len; ++i){ | |
++count[A[i]]; | |
} | |
i = 1; | |
while (i <= 2 * len){ | |
k = i; | |
while (k <= 2 * len){ | |
divisors[k] += count[i]; | |
k += i; | |
} | |
++i; | |
} | |
for (i = 0; i < len; ++i){ | |
result.push(0); | |
result[i] = len - divisors[A[i]]; | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment