title: Getting factorial of a large number
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1966077/calculate-the-factorial-of-an-arbitrarily-large-number-showing-all-the-digits">Calculate the factorial of an arbitrarily large number, showing all the digits</a>  </p>
  </blockquote>
  
  
  
  <p>This question might be asked thousand times here. I am repeating my question with a modification. I want to calculate factorial of a large number (<code>max range of the number=10^6</code>). Generally we uses a <code>for</code> loop from <code>i=1</code> to <code>i=number</code> and every time multiplying the old value to the new value. This is fine for small numbers but what if i have a large number? The range of <code>for</code> loop is increased now. Java primitive data type <code>int</code>, <code>long</code> can't handle the resultant large number. They simply overflows. Although i knew about <code>BigInteger</code> class, which can handle this large output but still <code>for</code> loop is not suiting better here for me. Can somebody please suggest me any tick, any hack to calculate factorial of a number? Below is the simple program which works fine for small number-</p>
  
  <pre><code>public long getFactorial(long number) {
      long factorial = 1;
      for (long i = 1; i &lt;= number; ++i) {
          factorial *= i;
      }
      return factorial;
  }
  </code></pre>