title: Don't understand how Codility CountDiv solution is correct
body: <p><a href="https://codility.com/programmers/task/count_div/" rel="noreferrer">Codility CountDiv Exercise</a>:</p>
  
  <p>Given a range A..B and value K, return the number of values in the range that are divisible by K. </p>
  
  <p>The example given is A = 6, B = 11 and K = 2. In the range 6 to 11, the numbers divisible by 2 are 6, 8 and 10, so the answer is 3. The solution required must be O(1) - so a simple calculation is needed.</p>
  
  <p>You can assume that A and B are in the range 0..2,000,000,000, K is 1..2,000,000,000 and that 0 &lt;= A &lt;= B.</p>
  
  <p>The accepted solution, that scores 100% is as follows:</p>
  
  <pre><code>int solution(int A, int B, int K)
  {
      int inclusive = ((A%K)==0) ? 1 : 0;
      return (B/K) - (A/K) + inclusive;
  }
  </code></pre>
  
  <p>Where I get confused is that when I test this solution with inputs A=0, B=0 and K=1, the result is 1? I would have thought that in the range 0 to 0, the number of values divisible by 1 is... 0! </p>
  
  <p>I thought this was an error and that the +1 for inclusive values of A should only be set if A is non-zero. </p>
  
  <p>So I submitted the following solution (test that A is non-zero):</p>
  
  <pre><code>int solution(int A, int B, int K)
  {
      int inclusive = (A &amp;&amp; (A%K)==0) ? 1 : 0;
      return (B/K) - (A/K) + inclusive;
  }
  </code></pre>
  
  <p>But this only scored 62% (50% correctness and 75% performance). Some of the  test cases it failed were:</p>
  
  <ul>
  <li>A = 0, B = 1, K = 11 - Got 0, expected 1</li>
  <li>A = 0, B = MAXINT, K in {1,MAXINT}, got 2000000000, expected 2000000001</li>
  </ul>
  
  <p>Can someone explain?</p>