title: How to check whether a no is factorial or not?
body: <p>I have a problem, then given some input number n, we have to check whether the no is factorial of some other no or not.  </p>
  
  <p>INPUT 24, OUTPUT true<br>
  INPUT 25, OUTPUT false<br>
  I have written the following program for it:-  </p>
  
  <pre><code>    int factorial(int num1) 
      {
          if(num1 &gt; 1)
          {
             return num1* factorial(num1-1) ; 
          }
          else
          {
            return 1 ; 
          }
      }
  
      int is_factorial(int num2) 
      {
          int fact = 0  ; 
          int i = 0  ;
          while(fact &lt; num2)
          {
               fact = factorial(i) ; 
               i++ ;
          }
          if(fact == num2)
          {
               return 0  ;
          }
          else
          {
               return -1;
          }
      }
  </code></pre>
  
  <p>Both these functions, seem to work correctly.<br>
  When we supply them for large inputs repeatedly, then the <code>is_factorial</code> will be repeatedly calling <code>factorial</code> which will be really a waste of time.<br>
  I have also tried maintaining a table for factorials   </p>
  
  <p><strong>So, my question, is there some more efficient way to check whether a number is factorial or not?</strong></p>