title: Nested loops into mathematical model to count number of operations
body: <p>I'm reading the book 'Algorithms - Fourth edition' by Sedgewick and Wayne and I must admit that some parts in the "Analysis of Algorithms" chapter are confusing me! This is probably caused by my lack of mathematical knowledge... Anyways!</p>
  
  <p>Somewhere in the book, there is an example of a program where the inner loop is said to be executed exactly N(N-1)(N-2)/6 times. Here it is:</p>
  
  <pre><code>    public static int count(int[] a) {
          int count = 0;
  
          for (int i = 0; i &lt; a.length; i++) {
              for (int j = i + 1; i &lt; a.length; j++) {
                  for (int k = j + 1; k &lt; a.length; k++) {
                      if (a[i] + a[j] + a[k] == 0) {
                          count++; 
                      } 
                  }
              }
          }
          return count;
      }
  </code></pre>
  
  <p>I am familiar with the big O notation but when it comes to counting the exact number of opreations in loops, I'm lost. I understand the N(N-1)(N-2) part but why do we have to divide by 6? What is the logic behind it?</p>
  
  <p>Any help would be greatly appreciated!</p>