Lesson 9 of 9 · Number Theory
Floor Functions
The floor function ⌊x⌋ turns a real number into the integer just below it. On the AMC it appears in three ways: counting multiples (⌊N/d⌋), computing the exponent of a prime in a factorial, and equations or sums where you have to track the integer and fractional parts separately. All three come from one idea: ⌊x⌋ = n means n ≤ x < n + 1.
Mark your status for this lesson:
Learning objectives
- Evaluate floors and ceilings, including negative arguments.
- Solve equations by writing x = n + f with n an integer and 0 ≤ f < 1.
- Count multiples and apply Legendre’s formula for prime exponents in factorials and trailing zeros.
- Evaluate sums of floors by grouping equal values or using symmetry, and handle ⌊√n⌋.
The core idea
⌊x⌋ is the greatest integer less than or equal to x, so ⌊x⌋ = n exactly when n ≤ x < n + 1. Every real x splits as x = ⌊x⌋ + {x} with fractional part 0 ≤ {x} < 1. Adding an integer passes through the floor: ⌊x + m⌋ = ⌊x⌋ + m. The ceiling ⌈x⌉ is the least integer at least x, and for negative numbers the floor moves away from zero (⌊−2.3⌋ = −3).
The number of positive multiples of d that are at most N is ⌊N/d⌋, and inclusion–exclusion combines these counts. Legendre’s formula gives the exponent of a prime p in n!: ⌊n/p⌋ + ⌊n/p²⌋ + ⌊n/p³⌋ + …, which is how trailing zeros are counted (use p = 5). To solve an equation, write x = n + f and split into cases on f (or on the range of x) to remove the floor. For sums of floors, group the terms that share a value, or count lattice pairs using symmetry. For ⌊√n⌋ = k, the integers n run from k² to (k + 1)² − 1, which is 2k + 1 numbers.
Defining inequality
⌊x⌋ = n ⇔ n ≤ x < n + 1
Turns any floor equation into an inequality for x.
Counting multiples
#{multiples of d ≤ N} = ⌊N/d⌋
Combine with inclusion–exclusion for ‘divisible by a or b’.
Legendre’s formula
v_p(n!) = ⌊n/p⌋ + ⌊n/p²⌋ + ⌊n/p³⌋ + …
The exponent of p in n!; trailing zeros of n! equal v₅(n!).
Worked example 1 — Counting solutions of a floor equation
Problem
How many integers n satisfy ⌊n/7⌋ = 3?
Key insight
Convert to the inequality 3 ≤ n/7 < 4.
Solution
21 ≤ n < 28, so n = 21, 22, …, 27: 7 integers.
Takeaway
Each value of ⌊n/d⌋ is taken by exactly d consecutive integers n.
Worked example 2 — Legendre’s formula
Problem
What is the greatest k such that 7^k divides 100!?
Key insight
Add the multiples of 7, of 49, and so on.
Solution
⌊100/7⌋ + ⌊100/49⌋ = 14 + 2 = 16 (343 > 100).
Takeaway
Each multiple of p contributes one factor, each multiple of p² one more, and so on.
Worked example 3 — Splitting into fractional part cases
Problem
Find all real x with ⌊x⌋ + ⌊2x⌋ = 7.
Key insight
Write x = n + f. The value of ⌊2x⌋ depends on whether f < 1/2.
Solution
If 0 ≤ f < 1/2 then ⌊2x⌋ = 2n and the equation is 3n = 7, impossible. If 1/2 ≤ f < 1 then ⌊2x⌋ = 2n + 1 and the equation is 3n + 1 = 7, so n = 2. Therefore 2.5 ≤ x < 3.
Takeaway
Floors of multiples of x change value at the multiples of 1/k; split the fractional part there.
Worked example 4 — Counting with inclusion–exclusion
Problem
How many positive integers at most 1000 are divisible by 6 but not by 4?
Key insight
Multiples of 6 that are also multiples of 4 are multiples of 12.
Solution
⌊1000/6⌋ − ⌊1000/12⌋ = 166 − 83 = 83.
Takeaway
‘Divisible by a but not b’ is the count for a minus the count for lcm(a, b).
Strategy notes
Convert to inequalities
Replace ⌊f(x)⌋ = n by n ≤ f(x) < n + 1 and solve; every floor problem then becomes an ordinary inequality problem.
Group by value
In a sum of floors, many consecutive terms are equal. Count how many terms take each value instead of evaluating them one at a time.
Common mistakes
Rounding negatives toward zero
⌊−2.3⌋ is −3, not −2. The floor always goes down.
Stopping Legendre’s formula early
Include the higher powers p², p³, … (for 150! the trailing zeros are 30 + 6 + 1 = 37, not 30).
Dropping the strict end
⌊x⌋ = n gives n ≤ x < n + 1; the upper endpoint is not included.
Practice
19 questions across four difficulty tiers, each with a single answer. 2 questions use the five-choice (A)–(E) format, as on the real exam. Up to three tries per question before the solution is shown.