// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
import java.math.BigInteger;

public class PowMod {
    public static void main(String[] args) {
        System.out.println(powmod(41, 77, 221));
    }
    public static int powmod(int a, int b, int c) {
        BigInteger i1 = new BigInteger(Integer.toString(a));
        BigInteger i2 = new BigInteger(Integer.toString(b));
        BigInteger i3 = new BigInteger(Integer.toString(c));
        return i1.modPow(i2,i3).intValue();
    }
}
