title: how to find factorial of a really big number
body: <p>I am trying to find out the output of this question but its not working, when n goes to 10^6 as it's taking a lot of time 
  is there any way to find it quicker?</p>
  
  <p>find the trailing zeros of factorial of n
  where 
  1&lt;= n &lt;=10^6</p>
  
  <p>here is my code :</p>
  
  <pre><code>     public static void main(String[] args) {
              test t=new test();                 
              Scanner input =new Scanner(System.in);
              int m=input.nextInt();               
              String x=t.factorial(m).toString();
              int count=0;
              for(int i=x.length()-1;i&gt;0;i--){
                      if(x.charAt(i)=='0')
                              count++;
                      else{
                              i=0;
                      }
              }
              System.out.println(count);
  
      }
  
      BigInteger factorial(int num){
              BigInteger temp = BigInteger.ONE;
              for(int i=1;i&lt;=num;i++)
                      temp = temp.multiply(new BigInteger(i + ""));
              return temp;
      }
  </code></pre>