Skip to content

Instantly share code, notes, and snippets.

@adicuco
Created June 16, 2018 14:49
Show Gist options
  • Select an option

  • Save adicuco/a2623fa4345af5fb6f2d272ec86e6fb7 to your computer and use it in GitHub Desktop.

Select an option

Save adicuco/a2623fa4345af5fb6f2d272ec86e6fb7 to your computer and use it in GitHub Desktop.
100% solution for Count Div Task on Codility
function solution(A, B, K) {
if (A == B) return A % K == 0 ? 1 : 0;
if (K == 1) return B - A + 1;
var count = 0;
var start = 0;
for (var i = A; i <= B; i++) {
if (i % K == 0) {
count++;
start = i;
break;
}
}
for (; start + K <= B; start += K) {
count++;
}
return count;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment