Created
June 16, 2018 14:49
-
-
Save adicuco/a2623fa4345af5fb6f2d272ec86e6fb7 to your computer and use it in GitHub Desktop.
100% solution for Count Div Task on Codility
This file contains hidden or 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, 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