Pow and mod function optimization
<p>I need to create an optimized function to count <strong>Math.pow(a,b) % c;</strong> in Javascript;
<br /> There's no problems while counting small numbers like: <br /> <code>Math.pow(2345,123) % 1234567;</code>
<br /> But if you try to count:<br /> <code>Math.pow(2345678910, 123456789) % 1234567;</code><br /> you'll get incorrect result because of Math.pow() function result that cannot count up "big" numbers;
<br />My solution was: </p>

<pre><code>function powMod(base, pow, mod){
    var i, result = 1;
    for ( i = 0; i &lt; pow; i++){
        result *= base;
        result %= mod;
    }
return result;
</code></pre>

<p>Though it needs a lot of time to be counted;<br />
Is it possible to optimized it somehow or find more rational way to count up <strong>Math.pow(a, b) % c;</strong> for "big" numbers? (I wrote "big" because they are not really bigIntegers);</p>
