Gradient

Courses

∇\nabla∇The maths behind AI0/72
π\piπMaths0/84
⋆\star⋆AI for everyone0/10
Γ\GammaΓGame theory0/49
py\texttt{py}pyPython for AI0/15
y^\hat{y}y^​Build your own AI0/15
All courses

Tuition

My tuitionOlympiad trackCompetitions

Practice

ProjectsAsk a questionTrain on a GPUExplorationsMaths StoriesUnsolved problemsPlaygroundScience labsMock testsOlympiad

Reference

GlossaryBlogDiscoveries
Competitions › IOQM › unit 1 of 14

Number theory

IOQM · All sections · about 7 minutes

Olympiad number theory is about divisibility, primes, remainders and digits. The key tool is modular arithmetic: working only with remainders.

Look for cycles. Last digits of powers repeat, remainders of powers repeat, and once you find the cycle length you can jump straight to a huge power.

In this lesson

  1. Divisibility and prime factors
  2. Working with remainders
  3. Digits and last digits
  4. Worked examples
  5. Where marks are lost
  6. Check yourself

1Divisibility and prime factors

Every whole number above 1 splits into primes in exactly one way. From n = p^a × q^b × r^c you get everything: the number of divisors (a + 1)(b + 1)(c + 1), whether n is a square (all powers even), and the gcd and lcm of two numbers (smallest and largest powers).

gcd(a, b) × lcm(a, b) = a × b. The Euclidean algorithm finds the gcd fast: gcd(a, b) = gcd(b, a mod b).

2Working with remainders

Modular arithmetic keeps only remainders: if a ≡ b (mod m), you can add, subtract and multiply both sides. To find a huge power’s remainder, find a small power that leaves 1 and use cycles.

Fermat’s little theorem: a^(p−1) ≡ 1 (mod p) for a prime p not dividing a. Squares leave only 0 or 1 mod 4 and 0, 1 or 4 mod 8, which kills many equations at once.

3Digits and last digits

A number is divisible by 9 exactly when its digit sum is; by 11 when the alternating digit sum is. Last digits of powers cycle with length 1, 2 or 4.

Trailing zeros of n! = ⌊n/5⌋ + ⌊n/25⌋ + ⌊n/125⌋ + …, because each zero needs a factor of 5.

Worked examples

  1. Example 1How many trailing zeros does 100! have?

    1. ⌊100/5⌋ = 20.
    2. ⌊100/25⌋ = 4.
    3. ⌊100/125⌋ = 0.

    Answer: 24

  2. Example 2Find the remainder when 3¹⁰⁰ is divided by 7.

    1. 3⁶ ≡ 1 (mod 7) by Fermat.
    2. 100 = 6 × 16 + 4, so 3¹⁰⁰ ≡ 3⁴ = 81.
    3. 81 = 7 × 11 + 4.

    Answer: 4

  3. Example 3Find the smallest n such that 1260n is a perfect square.

    1. 1260 = 2² × 3² × 5 × 7.
    2. The powers of 5 and 7 are odd.
    3. n = 5 × 7.

    Answer: 35

Where marks are lost

  • Forgetting ⌊n/25⌋ and higher terms for trailing zeros.
  • Using Fermat when the base shares a factor with the prime.
  • Counting divisors without the +1 for each power.

Exam tips

  • Last digits of 2, 3, 7 and 8 powers repeat every 4.
  • Number of divisors of p^a q^b r^c is (a + 1)(b + 1)(c + 1).
  • Fermat: aᵖ⁻¹ leaves remainder 1 on division by a prime p (if p does not divide a).

Practice questions

  1. What is the last digit of 7²⁰²⁶?

  2. How many positive divisors does 360 have?

  3. What is the remainder when 2¹⁰⁰ is divided by 7?

More worked examples

Try each one first, then open the working.

  1. Three traffic lights change every 12, 27 and 50 seconds. They all change together at 8:00 a.m. After how many seconds will they next change together?

    Show the working

    Start: Find the LCM of the three times.

    LCM(12, 27, 50) = 2700 s.

    Answer: 2700 s

  2. A floor 180 cm by 140 cm is to be covered with the largest possible square tiles, without cutting any. How many tiles are needed?

    Show the working

    Start: The tile side must divide both lengths: find the HCF.

    Largest tile side = HCF(180, 140) = 20 cm. Tiles = (180 ÷ 20) × (140 ÷ 20) = 9 × 7 = 63.

    Answer: 63

  3. All the whole numbers from 0 to 31 are written in 5-bit binary. How many 1s are written in total?

    Show the working

    Start: Count position by position.

    Each of the 5 positions is 1 in exactly half of the 32 numbers: 5 × 16 = 80.

    Answer: 80

  4. The clock shows the time now. What hour will it show 37 hours later? (Type a number from 1 to 12.)

    123456789101112
    Show the working

    Start: Only the remainder after dividing by 12 matters.

    37 = 3 × 12 + 1. Full 12s change nothing, so move 1 hours from 9: 10 o’clock.

    Answer: 10

Practise more

New questions every time, at exam level

Three traffic lights change every 12, 36 and 40 seconds. They all change together at 8:00 a.m. After how many seconds will they next change together?

s

Learn it properly

Full chapters with animations, each with an “Explained simply” version.

  • Number theory and puzzlesClass 10
  • Number theory and puzzlesClass 11

Sit a timed IOQM mock test

Next: Algebra