Function to return a raised to the power n with complexity O ( log ( n ) )
function powmod ( a , n ) { if ( ! n ) return 1 ; let pt = powmod ( a , parseInt ( n / 2 ) ) ; pt = ( pt * pt ) % mod ; if ( n % 2 ) return ( pt * a ) % mod ; else return pt ; }