title: Unable to calculate number of combinations due to very large factorial
body: <p>I am trying to calculate the number of combinations of the number of elements in a certain array. I need the exact number of combinations to use it as number of threads to be executed in the GPU.</p>
  
  <p>But the data is very big and the factorial can't be calculated for that big a number with any data type.</p>
  
  <p>Is there a way to calculate the number of combinations without having to find the factorial? Or a more efficient way to do so?</p>
  
  <p>It summarizes the problem:</p>
  
  <pre><code>int no_of_combinations = combination(500,2);
  public static int factorial(int m)
  {
          int x = 1;
  
          for (int i = m; i &gt; 0; i--)
              x = x * i;
  
          return x;
  }
  public static int combination(int m, int n)
  {
      int x = 0;
      x = factorial(m) / (factorial(n) * factorial(m - n));
      return x;
  }
  </code></pre>