pow ( base , exp , mod ) is used to find ( base ^ exp ) % mod fast -> O ( log ( exp ) )
static long pow ( long b , long exp , long mod ) { long ret = 1 ; while ( exp > 0 ) { if ( ( exp & 1 ) > 0 ) ret = ( ret * b ) % mod ; b = ( b * b ) % mod ; exp >>= 1 ; } return ret ; }