Skip to main content

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:

  1. Find pattern of remainders.
  2. Reduce exponent using cycle length.
  3. Use the matching remainder.

Fermat shortcut:

If p is prime and a is not divisible by p:
a^(p-1) mod p = 1