 <p>You should use the <a href="http://developer.android.com/reference/java/math/BigInteger.html#modPow%28java.math.BigInteger,%20java.math.BigInteger%29" rel="nofollow"><code>BigInteger.modPow</code></a> method or an equivalent solution that uses an efficient <a href="http://en.wikipedia.org/wiki/Modular_exponentiation" rel="nofollow">modular exponentiation</a> algorithm.</p>