Modular exponentiation is the remainder when an integer a (the base) is raised to the power m (the exponent), and divided by a positive integer n (the modulus);
that is, y = am mod n.
From the definition of division, it follows that 0 ≤ y < n.
To understand clearly, we can change the value of m for a particular value of a and modu (which represents the value of n).
For example, if we consider modu = 13 and a = 7, then by changing the value of m we can get the outputs as
7 (for m =1), 10 (for m = 2),
5 (for m = 3), 9 (for m = 4),
11 (for m =5), 12 (for m =6),....
Note:
To see the progression of the output, we can use the option "path of a^m".
Observations:
When a and n are coprime, i.e gcd(a,n) =1, we can see a^m for various values of m are different thus, we see a clear path.
For example, when n = 13 and a = 2, the outputs are, i.e.,
21 mod 12 = 2,
22 mod 12 = 4,
23 mod 12 = 8,
24 mod 12 = 3, ... .
Thus we see a clear path.
When a and n are not coprime, a^m for various values of m are not different thus we find that the results vary among few numbers.
For example, when n = 12 and a = 3, the outputs toggle between, 3 and 9, i.e.,