Java Number Power pow(int a, int b, int modulus)

Here you can find the source of pow(int a, int b, int modulus)

Description

Calculates a^b mod modulus

License

Open Source License

Declaration

public static int pow(int a, int b, int modulus) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from w w  w  . ja  va2 s  .c o m
     * Calculates a^b mod modulus
     */
    public static int pow(int a, int b, int modulus) {
        int p = 1;
        for (int i = 0; i < b; i++) {
            p = (p * a) % modulus;
        }
        return p;
    }

    /**
     * Calculates a^b mod modulus
     */
    public static long pow(long a, int b, long modulus) {
        long p = 1;
        for (int i = 0; i < b; i++) {
            p = (p * a) % modulus;
        }
        return p;
    }
}

Related

  1. Pow(float base, float exponent)
  2. pow(float x, int y)
  3. pow(float[] inData, float rate)
  4. pow(float[][] in)
  5. pow(int a, int b)
  6. pow(int b, int e)
  7. pow(int base, int exp)
  8. pow(int base, int exp)
  9. pow(int base, int exponent)