title: Java pow BigInteger implementation
body: <p>I am working on a cryptography implementation and part of the design includes the following:</p>
  
  <p>( (y^a)^b / (y^c)^b ) mod p</p>
  
  <p>I have the following snippet:</p>
  
  <pre><code>BigInteger yab = y.pow(ab.intValue());
  BigInteger ycb = y.pow(cb.intValue());
  
  BigInteger ans = (yab.divide(ycb)).mod(p);
  </code></pre>
  
  <p>It works fine for small integer. Once I replaced it with generated keys, the exponent grew so huge and I will hit the "BigInteger out of int range" error. I have tried the modPow function but the result is different.</p>
  
  <p>I understand that casting it to int has its limitation. Does that means my implementation is infeasible?</p>