src/com/michaelho/RandomizedAlgorithms/RA2.java
/**
         * Calculate modular inverse by applying Fermat's little theorem. This method
         * calculate The modular inverse of x^y.
         *
         * @param x The number as basis.
         * @param y The number of power.
         * @return The modular inverse of x^y.
         * */
Calculate modular inverse by applying Fermat's little theorem. This method
calculate The modular inverse of x^y.

@param x The number as basis.
@param y The number of power.
@return The modular inverse of x^y.
Calculate modular inverse by applying Fermat ' s little theorem . This method calculate The modular inverse of x^y . @param x The number as basis . @param y The number of power . @return The modular inverse of x^y .
int calculateModInverse(int x, int y) {
            RA1 ra1 = new RA1();
            if (ra1.gcd.euclidAlgorithm(x, y) != 1)
                return -1;
            else {
                return power(x, y - 2, y);
            }
        }
int calculateModInverse ( int x , int y ) { RA1 ra1 = new RA1 ( ) ; if ( ra1 . gcd . euclidAlgorithm ( x , y ) != 1 ) return - 1 ; else { return power ( x , y - 2 , y ) ; } }
Calculate modular inverse by applying Fermat's little theorem.
Calculate modular inverse by applying Fermat ' s little theorem .
// Based on Fermat's little theorem, if a and m are relatively prime, // then modulo inverse is x^(y-2) mod y.