potential SciMax Toolbox powerdisp

SciMax Toolbox >> power_mod

power_mod

Maxima Function

Calling Sequence

power_mod (a, n, m)

Description

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
potential SciMax Toolbox powerdisp