I have a % m.
I want to find ax % m.
This is what I have observed.
Let a = 6 and m = 4
a % m = 2
We can find a2 % m as (6 + 6 + 6 + 6 + 6 + 6) % m which is equal to
((6 % 4) + (6 % 4) + (6 % 4) + (6 % 4) + (6 % 4) + (6 % )) % 4 which is 0
This can be seen as 62 % 4 = (6 * (6 % 4) % 4
For 3 the above can be written as (6 * ((6 * (6 % 4)) % 4)) % 4
This can be done like that recursively.
Is there an efficient method than this ?