So the second way I do is,

this is the one I call derivative modular and exponentiation.

It is based on the following observation.

So you have two numbers x and y.

And if they are congruent to each other mod n and

then if I multiply them both by a, they are still congruent to each other.

So, following this observation, I can limit the value of the numbers,

which I do multiplication.

For example, I'm not going to multiply anything larger than n.

Whenever they are larger than n, I'm going to do a modular operation.

For the same example here, let's say I try to calculate 2 to the power 10 mod 10.

I start with this, which is 2 to the power 1, which is 2.

So this is fine, this is less than n, so I continue doing multiplication.

The second 2, 2 times 2 is 4.

This is still less than 10, so I do the multiplication.

4 times 2, which is 8, it is the third one.

And then 8 multiplied by 2 again becomes 16.