Function to return the modular inverse using Fermat 's little theorem
int mi ( int x ) { int p = mod - 2 ; int s = 1 ; while ( p != 1 ) { if ( p % 2 == 1 ) s = ( s * x ) % mod ; x = ( x * x ) % mod ; p /= 2 ; } return ( s * x ) % mod ; }