Remainders
Remainders
Rules:
(a+b) mod n = [(a mod n) + (b mod n)] mod n
(a-b) mod n = [(a mod n) - (b mod n)] mod n
(a*b) mod n = [(a mod n)*(b mod n)] mod n
Negative remainder handling:
-2 mod 7 = 5
Cyclic powers:
- Find pattern of remainders.
- Reduce exponent using cycle length.
- Use the matching remainder.
Fermat shortcut:
If p is prime and a is not divisible by p:
a^(p-1) mod p = 1