// 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) 
public class PowModAlt {
    public static void main(String[] args) {
        System.out.println(powmod(41, 77, 221));
    }
    public static int powmod(int a, int b, int c) {
        if(b > 3) {
            return ((powmod(a, b/2, c) * powmod(a, b- b/2, c)) % c);
        } else {
            return (int)(Math.pow(a, b) % c);
        }
    }
}
