Here you can find the source of pow(int a, int b, int modulus)
public static int pow(int a, int b, int modulus)
//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; } }