src/com/michaelho/RandomizedAlgorithms/RA1.java
/**
         * Modular exponentiation, the power in Modular Arithmetic.
         * Reference: https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/
         *
         * @param x The number as base to be calculated.
         * @param y The exponential number.
         * @param N The mod number.
         * @return The result of modular exponential.
         * */
Modular exponentiation, the power in Modular Arithmetic.

@param x The number as base to be calculated.
@param y The exponential number.
@param N The mod number.
@return The result of modular exponential.
Modular exponentiation the power in Modular Arithmetic . @param x The number as base to be calculated . @param y The exponential number . @param N The mod number . @return The result of modular exponential .
int modularExp(int x, int y, int N) {
            int res = 1;
            x = x % N;
            while (y > 0) {
                if (y % 2 == 1)
                    res = res * x % N;
                y = y / 2;
                x = x * x % N;
            }
            return res;
        }
int modularExp ( int x , int y , int N ) { int res = 1 ; x = x % N ; while ( y > 0 ) { if ( y % 2 == 1 ) res = res * x % N ; y = y / 2 ; x = x * x % N ; } return res ; }
Modular exponentiation, the power in Modular Arithmetic.
Modular exponentiation the power in Modular Arithmetic .
// If y is odd, multiply x with result // y must be even now