computing ( a ^ b ) % c
function modpow ( base , exp , modulus ) { base %= modulus ; let result = 1 ; while ( exp > 0 ) { if ( ( exp & 1 ) > 0 ) result = ( result * base ) % modulus ; base = ( base * base ) % modulus ; exp >>= 1 ; } return result ; }