title: Calculating large power of a number
body: <pre><code>#include&lt;iostream&gt;
  #include&lt;cstdio&gt;
  #define M 1000000007
  using namespace std;
  
  long long int power(int a,int b)
  {
      if(b==0)
          return 1;
      else if(b==1)
          return a;
      else if(b%2==0)
          return power((a*a)%M,b/2);
      else
          return (power((a*a)%M,b/2)*a)%M;
  }
  </code></pre>
  
  <p>In this function when I pass a=2, b>31, it always returns 0.for b=31 i got 147483634.can you tell where the problem is?</p>
  
  <p>or can you tell another method for calculating large powers of a number.</p>