Maxima Function
power_mod (a, n, m)
Uses a modular algorithm to compute a^n mod m
where a and n are integers and m is a positive integer.
If n is negative, inv_mod
is used to find the modular inverse.
(%i1) power_mod(3, 15, 5); (%o1) 2 (%i2) mod(3^15,5); (%o2) 2 (%i3) power_mod(2, -1, 5); (%o3) 3 (%i4) inv_mod(2,5); (%o4) 3