Modular Arithmetic — The Maths of Remainders

Learn modular arithmetic with clear explanations, worked examples, and practice problems.

CBSE JEE-MAIN NEET 10 min read

Modular arithmetic is the mathematics of remainders — and it shows up everywhere from clock arithmetic to computer science to number theory problems in JEE. Once you understand the core idea, you’ll find it surprisingly powerful for solving problems that look impossibly complex at first glance. Finding the last digit of 71007^{100}? Finding the remainder when 2502^{50} is divided by 7? Modular arithmetic handles these in seconds.

Key Terms & Definitions

Modulo operation: amodma \mod m is the remainder when aa is divided by mm. For example, 17mod5=217 \mod 5 = 2 because 17=3×5+217 = 3 \times 5 + 2.

Congruence: We say ab(modm)a \equiv b \pmod{m} (read: “a is congruent to b modulo m”) if mm divides (ab)(a - b). This means aa and bb give the same remainder when divided by mm.

Examples:

  • 172(mod5)17 \equiv 2 \pmod{5} (both give remainder 2 when divided by 5)
  • 250(mod5)25 \equiv 0 \pmod{5} (25 is divisible by 5)
  • 34(mod7)-3 \equiv 4 \pmod{7} (since 34=7-3 - 4 = -7, divisible by 7)

Note on negative numbers: In modular arithmetic, we typically prefer positive remainders. 3mod7=4-3 \mod 7 = 4 (since 3=1×7+4-3 = -1 \times 7 + 4).

Modulus (or modulo): The number mm in (modm)\pmod{m}.

Residue: The remainder itself — the value of amodma \mod m.

Complete Residue System modulo m: The set {0,1,2,...,m1}\{0, 1, 2, ..., m-1\} — one representative from each congruence class.

Methods and Concepts

Properties of Congruences

If ab(modm)a \equiv b \pmod{m} and cd(modm)c \equiv d \pmod{m}, then:

  1. Addition: a+cb+d(modm)a + c \equiv b + d \pmod{m}
  2. Subtraction: acbd(modm)a - c \equiv b - d \pmod{m}
  3. Multiplication: acbd(modm)ac \equiv bd \pmod{m}
  4. Powers: anbn(modm)a^n \equiv b^n \pmod{m} for any positive integer nn

These properties are the engine of all modular arithmetic calculations. They let us reduce large numbers to small residues at each step.

Finding Last Digits (mod 10)

The last digit of any number is its remainder when divided by 10 — that’s nmod10n \mod 10.

The last digit of powers of 7:

71=77^1 = 7, 72=497^2 = 49 (last digit 9), 73=3437^3 = 343 (last digit 3), 74=24017^4 = 2401 (last digit 1), 75=...17^5 = ...1 (last digit 7)

The pattern repeats every 4 powers: 7, 9, 3, 1, 7, 9, 3, 1, …

Last digit of 71007^{100}: 100÷4=25100 \div 4 = 25 remainder 0, so 71007^{100} has same last digit as 74=17^4 = 1.

Last digit of 71007^{100} is 1.

This cyclicity of last digits is fundamental. Powers of 2 cycle with period 4 (2, 4, 8, 6). Powers of 3 cycle with period 4 (3, 9, 7, 1). Powers of 4 cycle with period 2 (4, 6). Powers of 5 always end in 5.

Fermat’s Little Theorem

For a prime pp and integer aa with gcd(a,p)=1\gcd(a, p) = 1:

ap11(modp)a^{p-1} \equiv 1 \pmod{p}

Immediate application: apa(modp)a^p \equiv a \pmod{p}

Example: Find 250(mod7)2^{50} \pmod{7}

77 is prime, gcd(2,7)=1\gcd(2,7) = 1, so 261(mod7)2^6 \equiv 1 \pmod{7} (Fermat’s)

50=8×6+250 = 8 \times 6 + 2

250=(26)8×2218×44(mod7)2^{50} = (2^6)^8 \times 2^2 \equiv 1^8 \times 4 \equiv 4 \pmod{7}

Remainder is 4.

Euler’s Theorem (Generalisation)

For gcd(a,m)=1\gcd(a, m) = 1:

aϕ(m)1(modm)a^{\phi(m)} \equiv 1 \pmod{m}

where ϕ(m)\phi(m) is Euler’s totient function (count of integers from 1 to mm coprime to mm).

For prime pp: ϕ(p)=p1\phi(p) = p-1, recovering Fermat’s theorem.

For ϕ(m)\phi(m) calculation:

  • ϕ(pk)=pkpk1=pk1(p1)\phi(p^k) = p^k - p^{k-1} = p^{k-1}(p-1)
  • ϕ(mn)=ϕ(m)ϕ(n)\phi(mn) = \phi(m)\phi(n) when gcd(m,n)=1\gcd(m,n) = 1 (multiplicative)

Example: ϕ(12)=ϕ(4)ϕ(3)=2×2=4\phi(12) = \phi(4)\phi(3) = 2 \times 2 = 4. The integers 1–12 coprime to 12 are: 1, 5, 7, 11 — indeed 4 of them.

Chinese Remainder Theorem (CRT)

If m1,m2,...,mkm_1, m_2, ..., m_k are pairwise coprime and N=m1m2mkN = m_1 m_2 \cdots m_k, then for any a1,a2,...,aka_1, a_2, ..., a_k, there is a unique xx with 0 \leq x < N such that:

xa1(modm1),xa2(modm2),...,xak(modmk)x \equiv a_1 \pmod{m_1}, \quad x \equiv a_2 \pmod{m_2}, \quad ..., \quad x \equiv a_k \pmod{m_k}

Example: Find xx such that x2(mod3)x \equiv 2 \pmod{3} and x3(mod5)x \equiv 3 \pmod{5}.

List multiples: x=2,5,8,11,14,17,20,23...x = 2, 5, 8, 11, 14, 17, 20, 23... (satisfying first condition) Check which gives remainder 3 when divided by 5: 8mod5=38 \mod 5 = 3. ✓

Answer: x=8x = 8 (and x=8+15kx = 8 + 15k for any integer kk)

Solved Examples

Easy — CBSE Level

Q: What is the remainder when 2102^{10} is divided by 3?

21(mod3)2 \equiv -1 \pmod{3}

210(1)10=1(mod3)2^{10} \equiv (-1)^{10} = 1 \pmod{3}

Remainder = 1. (No need to compute 210=10242^{10} = 1024; just work with the residue.)

Medium — JEE Main Level

Q: Find the last two digits of 31003^{100} (i.e., 3100(mod100)3^{100} \pmod{100})

Use Euler: ϕ(100)=ϕ(4)ϕ(25)=2×20=40\phi(100) = \phi(4)\phi(25) = 2 \times 20 = 40

gcd(3,100)=1\gcd(3, 100) = 1, so 3401(mod100)3^{40} \equiv 1 \pmod{100}

100=2×40+20100 = 2 \times 40 + 20

3100=(340)2×3201×320(mod100)3^{100} = (3^{40})^2 \times 3^{20} \equiv 1 \times 3^{20} \pmod{100}

310=5904949(mod100)3^{10} = 59049 \equiv 49 \pmod{100}

320=(310)2492=24011(mod100)3^{20} = (3^{10})^2 \equiv 49^2 = 2401 \equiv 1 \pmod{100}

Last two digits of 31003^{100} are 01.

Hard — JEE Advanced Level

Q: If pp is a prime and pa2p | a^2, prove that pap | a.

Suppose pap \nmid a. Then gcd(p,a)=1\gcd(p, a) = 1 (since pp is prime, its only divisors are 1 and pp). But pa2p | a^2, meaning a20(modp)a^2 \equiv 0 \pmod p. Since Z/pZ\mathbb{Z}/p\mathbb{Z} is a field (for prime pp), it has no zero divisors. So aa0(modp)a \cdot a \equiv 0 \pmod p implies a0(modp)a \equiv 0 \pmod p, i.e., pap | a. Contradiction. Hence pap | a. \square

This result is the key lemma in the standard proof that p\sqrt{p} is irrational for any prime pp.

Exam-Specific Tips

JEE Main: Remainder problems are almost guaranteed. Key: know the cyclicity patterns for powers (units digits cycle with period dividing 4 for most digits). For mod 7, 11, 13, use Fermat’s Little Theorem. For mod 6, use direct computation since ϕ(6)=2\phi(6) = 2.

CBSE Class 10: “Divisibility and remainders” questions often ask: is n21n^2 - 1 divisible by 8 for odd nn? Answer: Yes — n1,3,5,7(mod8)n \equiv 1, 3, 5, 7 \pmod 8 for odd nn, and n21(mod8)n^2 \equiv 1 \pmod 8 for all of these.

Common Mistakes to Avoid

Mistake 1: ab(modm)a \equiv b \pmod m does NOT mean a=ba = b. It means they have the same remainder. 172(mod5)17 \equiv 2 \pmod 5, but 17217 \neq 2.

Mistake 2: You cannot divide freely in modular arithmetic. 64(mod2)6 \equiv 4 \pmod 2 does NOT mean 32(mod1)3 \equiv 2 \pmod 1 after dividing by 2. Division is allowed only when the divisor is coprime to the modulus.

Mistake 3: Forgetting that powers cycle — computing 71007^{100} by brute force instead of recognising the cycle of length 4 in the units digit.

Mistake 4: Applying Fermat’s Little Theorem with pp non-prime. FLT requires pp to be prime. For composite moduli, use Euler’s theorem with ϕ(m)\phi(m).

Mistake 5: Getting the remainder of a negative number wrong. 1mod5=4-1 \mod 5 = 4 (not -1). In modular arithmetic, remainders are always non-negative.

Practice Questions

Q1. Find the remainder when 100!100! is divided by 101.

101 is prime. By Wilson’s Theorem: (p1)!1(modp)(p-1)! \equiv -1 \pmod p for prime pp. So 100!1100(mod101)100! \equiv -1 \equiv 100 \pmod{101}. Remainder = 100.

Q2. What is the units digit of 320253^{2025}?

Powers of 3 cycle: 3, 9, 7, 1 (period 4). 2025÷4=5062025 \div 4 = 506 remainder 1. So 320253^{2025} has same units digit as 31=33^1 = 3. Units digit = 3.

Q3. Show that n2+nn^2 + n is always even.

n2+n=n(n+1)n^2 + n = n(n+1). Among any two consecutive integers, one is even. So n(n+1)n(n+1) is always even. Alternatively: n0n \equiv 0 or 1(mod2)1 \pmod 2. In either case, n2+n0(mod2)n^2 + n \equiv 0 \pmod 2.

Q4. Find the last digit of 13202413^{2024}.

Units digit depends on 320243^{2024} (since 1313 has units digit 3). Cycle of 3: period 4. 2024÷4=5062024 \div 4 = 506 remainder 0. Same as 343^4, units digit 1. Last digit = 1.

Q5. Find xx such that x1(mod4)x \equiv 1 \pmod 4 and x2(mod3)x \equiv 2 \pmod 3, with 0 \leq x < 12.

From first: x=1,5,9x = 1, 5, 9. Check mod 3: 5mod3=25 \mod 3 = 2. ✓ x = 5.

Q6. Prove that 7(231)7 | (2^3 - 1) and find the smallest n>1n > 1 such that 7(2n1)7 | (2^n - 1).

231=72^3 - 1 = 7, so 777 | 7. ✓ By Fermat: 261(mod7)2^6 \equiv 1 \pmod 7, so 7(261)7 | (2^6 - 1). Check: 21=2,22=4,23=1(mod7)2^1=2, 2^2=4, 2^3=1 \pmod 7. So order of 2 mod 7 is 3. Smallest n>1n > 1: n = 3.

Q7. What is the remainder when 1!+2!+3!+...+100!1! + 2! + 3! + ... + 100! is divided by 10?

n!0(mod10)n! \equiv 0 \pmod{10} for n5n \geq 5 (contains factors 2 and 5). So remainder = (1!+2!+3!+4!)mod10=(1+2+6+24)mod10=33mod10=3(1! + 2! + 3! + 4!) \mod 10 = (1 + 2 + 6 + 24) \mod 10 = 33 \mod 10 = \textbf{3}.

Q8. If pp and qq are primes and p+q=60p + q = 60, find all possible pairs.

One of pp or qq must be 2 (since if both are odd, their sum is even only if both odd — but 60=even60 = \text{even}, so either both even or both odd; both even means both = 2, impossible for two primes summing to 60). So one is 2: q=58=2×29q = 58 = 2 \times 29. Not prime. OR: both can be odd, and sum to even (60). Try systematically: (7, 53) — both prime ✓; (11, 49) — 49 = 7², not prime; (13, 47) — both prime ✓; (17, 43) — both prime ✓; (19, 41) — both prime ✓; (23, 37) — both prime ✓; (29, 31) — both prime ✓. Pairs: (7,53), (13,47), (17,43), (19,41), (23,37), (29,31).

FAQs

Q: What’s the difference between mod and remainder in programming?

In mathematics, amodma \mod m is always non-negative. In many programming languages, the % operator can return negative values for negative inputs. In Python, 3%5=2-3 \% 5 = 2 (matches mathematical modulo). In C/Java, 3%5=3-3 \% 5 = -3 (truncated division). This matters when translating maths to code.

Q: Why does Fermat’s Little Theorem have p1p-1 in the exponent?

Because the nonzero elements of Z/pZ\mathbb{Z}/p\mathbb{Z} form a multiplicative group of order p1p-1. By Lagrange’s theorem, the order of any element divides the group order. So ap11a^{p-1} \equiv 1. This is a clean algebraic reason.

Q: Is modular arithmetic used in real life?

Absolutely. RSA encryption — which secures every HTTPS connection — is based on Euler’s theorem in modular arithmetic. ISBN barcodes use mod 10. Credit card validation uses mod 10 (Luhn algorithm). GPS error correction uses modular codes.

Q: How do I find ϕ(m)\phi(m) quickly?

Factorise mm into prime powers: m=p1a1p2a2m = p_1^{a_1} p_2^{a_2} \cdots. Then ϕ(m)=m(11/pi)\phi(m) = m \prod(1 - 1/p_i) over distinct prime factors. Example: ϕ(60)=60(11/2)(11/3)(11/5)=60×1/2×2/3×4/5=16\phi(60) = 60(1-1/2)(1-1/3)(1-1/5) = 60 \times 1/2 \times 2/3 \times 4/5 = 16.

Q: When can we cancel in modular arithmetic?

If acbc(modm)ac \equiv bc \pmod m and gcd(c,m)=1\gcd(c, m) = 1, then ab(modm)a \equiv b \pmod m. If gcd(c,m)=d1\gcd(c, m) = d \neq 1, we can only cancel cc if we also reduce the modulus: ab(modm/d)a \equiv b \pmod{m/d}.