Academy
Maths›Number Theory›Dirichlet›The Floor Function

The Floor Function

The floor function strips away the fractional part of a number. It turns continuous quantities into discrete ones — and that is exactly what counting problems need.

How many multiples of 7 are there between 1 and 100?

You could list them: 7, 14, 21, ..., 98. Count: 14.

Or you could compute ⌊100/7⌋=14\lfloor 100/7 \rfloor = 14 directly.

The floor function is the bridge between division and counting. Every time a problem asks "how many integers satisfy...", the floor function is either the answer or the tool that finds it.


The definition

The floor of a real number xx, written ⌊x⌋\lfloor x \rfloor, is the largest integer that does not exceed xx.

⌊x⌋=max⁡{n∈Z:n≤x}\lfloor x \rfloor = \max\{n \in \mathbb{Z} : n \leq x\}

Equivalently: ⌊x⌋=n\lfloor x \rfloor = n where nn is the unique integer satisfying n≤x<n+1n \leq x < n+1.

Examples:

  • ⌊3.7⌋=3\lfloor 3.7 \rfloor = 3
  • ⌊5⌋=5\lfloor 5 \rfloor = 5
  • ⌊−2.3⌋=−3\lfloor -2.3 \rfloor = -3 (not −2-2 — the floor goes down)
  • ⌊π⌋=3\lfloor \pi \rfloor = 3
  • ⌊−π⌋=−4\lfloor -\pi \rfloor = -4

The fractional part is defined as {x}=x−⌊x⌋\{x\} = x - \lfloor x \rfloor. Always satisfies 0≤{x}<10 \leq \{x\} < 1.


Basic properties

P1. ⌊x⌋≤x<⌊x⌋+1\lfloor x \rfloor \leq x < \lfloor x \rfloor + 1

P2. ⌊x⌋=x  ⟺  x\lfloor x \rfloor = x \iff x is an integer.

P3. ⌊x+n⌋=⌊x⌋+n\lfloor x + n \rfloor = \lfloor x \rfloor + n for any integer nn.

Proof. Adding an integer shifts xx without changing its fractional part. ■\blacksquare

P4. ⌊x⌋+⌊y⌋≤⌊x+y⌋≤⌊x⌋+⌊y⌋+1\lfloor x \rfloor + \lfloor y \rfloor \leq \lfloor x + y \rfloor \leq \lfloor x \rfloor + \lfloor y \rfloor + 1

Proof. Write x=⌊x⌋+{x}x = \lfloor x \rfloor + \{x\} and y=⌊y⌋+{y}y = \lfloor y \rfloor + \{y\}. Then x+y=(⌊x⌋+⌊y⌋)+({x}+{y})x+y = (\lfloor x\rfloor + \lfloor y\rfloor) + (\{x\}+\{y\}). Since 0≤{x}+{y}<20 \leq \{x\}+\{y\} < 2, the floor of x+yx+y is either ⌊x⌋+⌊y⌋\lfloor x\rfloor + \lfloor y\rfloor or ⌊x⌋+⌊y⌋+1\lfloor x\rfloor + \lfloor y\rfloor + 1. ■\blacksquare

P5. ⌊x/n⌋=⌊⌊x⌋/n⌋\lfloor x/n \rfloor = \lfloor \lfloor x \rfloor / n \rfloor for positive integer nn.

This one is subtle but very useful — you can take the floor inside or outside, result is the same.

Common mistake. ⌊x+y⌋≠⌊x⌋+⌊y⌋\lfloor x + y \rfloor \neq \lfloor x \rfloor + \lfloor y \rfloor in general. Example: ⌊0.6+0.7⌋=⌊1.3⌋=1\lfloor 0.6 + 0.7 \rfloor = \lfloor 1.3 \rfloor = 1 but ⌊0.6⌋+⌊0.7⌋=0\lfloor 0.6 \rfloor + \lfloor 0.7 \rfloor = 0.


Counting with the floor function

Multiples of dd up to nn: The number of positive multiples of dd that do not exceed nn is ⌊n/d⌋\lfloor n/d \rfloor.

Proof. The multiples are d,2d,3d,…d, 2d, 3d, \ldots The largest one ≤n\leq n is d⋅⌊n/d⌋d \cdot \lfloor n/d \rfloor, so there are ⌊n/d⌋\lfloor n/d \rfloor of them. ■\blacksquare

Integers in an interval: The number of integers in [a,b][a, b] is ⌊b⌋−⌈a⌉+1\lfloor b \rfloor - \lceil a \rceil + 1, where ⌈a⌉=−⌊−a⌋\lceil a \rceil = -\lfloor -a \rfloor is the ceiling function.

For integers a≤ba \leq b: count is b−a+1b - a + 1.


Legendre's formula — highest power of a prime in n!n!

Theorem. The largest power of prime pp dividing n!n! is:

vp(n!)=∑k=1∞⌊npk⌋v_p(n!) = \sum_{k=1}^{\infty} \left\lfloor \frac{n}{p^k} \right\rfloor

(The sum is finite since ⌊n/pk⌋=0\lfloor n/p^k \rfloor = 0 for pk>np^k > n.)

Why. Among 1,2,…,n1, 2, \ldots, n:

  • ⌊n/p⌋\lfloor n/p \rfloor multiples of pp — each contributes at least one factor of pp
  • ⌊n/p2⌋\lfloor n/p^2 \rfloor multiples of p2p^2 — each contributes an extra factor
  • ⌊n/p3⌋\lfloor n/p^3 \rfloor multiples of p3p^3 — each contributes yet another
  • and so on.

Total factors of pp in n!n! is the sum. ■\blacksquare

Example. Highest power of 2 in 100!100!:

⌊1002⌋+⌊1004⌋+⌊1008⌋+⌊10016⌋+⌊10032⌋+⌊10064⌋=50+25+12+6+3+1=97\left\lfloor \frac{100}{2} \right\rfloor + \left\lfloor \frac{100}{4} \right\rfloor + \left\lfloor \frac{100}{8} \right\rfloor + \left\lfloor \frac{100}{16} \right\rfloor + \left\lfloor \frac{100}{32} \right\rfloor + \left\lfloor \frac{100}{64} \right\rfloor = 50 + 25 + 12 + 6 + 3 + 1 = 97

So 297∣100!2^{97} \mid 100! but 298∤100!2^{98} \nmid 100!.

Application. Number of trailing zeros in n!n! = v5(n!)v_5(n!) (since v2>v5v_2 > v_5 always, pairs of 2 and 5 form 10s).

Trailing zeros in 100!100!: ⌊100/5⌋+⌊100/25⌋=20+4=24\lfloor 100/5 \rfloor + \lfloor 100/25 \rfloor = 20 + 4 = 24.


Hermite's identity

⌊x⌋+⌊x+1n⌋+⌊x+2n⌋+⋯+⌊x+n−1n⌋=⌊nx⌋\lfloor x \rfloor + \lfloor x + \tfrac{1}{n} \rfloor + \lfloor x + \tfrac{2}{n} \rfloor + \cdots + \lfloor x + \tfrac{n-1}{n} \rfloor = \lfloor nx \rfloor

Proof. Write x=m+{x}x = m + \{x\} where m=⌊x⌋m = \lfloor x \rfloor. The left side shifts by integers summing to m⋅nm \cdot n plus contributions from the fractional parts. The fractional part {x}\{x\} falls in exactly one interval [k/n,(k+1)/n)[k/n, (k+1)/n), and the identity reduces to a counting argument on the fractional parts. ■\blacksquare

Special case (n=2n=2): ⌊x⌋+⌊x+12⌋=⌊2x⌋\lfloor x \rfloor + \lfloor x + \frac{1}{2} \rfloor = \lfloor 2x \rfloor.


Worked problems

Problem 1. How many integers from 1 to 1000 are divisible by 3 but not by 7?

Divisible by 3: ⌊1000/3⌋=333\lfloor 1000/3 \rfloor = 333.

Divisible by both 3 and 7 (i.e., by 21): ⌊1000/21⌋=47\lfloor 1000/21 \rfloor = 47.

Answer: 333−47=286333 - 47 = 286.

Problem 2. Find the number of trailing zeros in 50!50!.

⌊50/5⌋+⌊50/25⌋=10+2=12\lfloor 50/5 \rfloor + \lfloor 50/25 \rfloor = 10 + 2 = 12.

Problem 3. Prove: ⌊n⌋\lfloor \sqrt{n} \rfloor equals the number of perfect squares ≤n\leq n.

Perfect squares ≤n\leq n: 12,22,…,k21^2, 2^2, \ldots, k^2 where k2≤n<(k+1)2k^2 \leq n < (k+1)^2. So k=⌊n⌋k = \lfloor \sqrt{n} \rfloor. ■\blacksquare

Problem 4. Find ∑k=1100⌊k⌋\displaystyle\sum_{k=1}^{100} \lfloor \sqrt{k} \rfloor.

⌊k⌋=m\lfloor \sqrt{k} \rfloor = m when m2≤k<(m+1)2m^2 \leq k < (m+1)^2, i.e., for 2m+12m+1 values of kk.

∑k=1100⌊k⌋=∑m=19m⋅(2m+1)+10⋅1\sum_{k=1}^{100} \lfloor \sqrt{k} \rfloor = \sum_{m=1}^{9} m \cdot (2m+1) + 10 \cdot 1

(For m=1m=1 to 99: each value holds for 2m+12m+1 integers. For m=10m=10: only k=100k=100.)

=∑m=19(2m2+m)+10=2⋅9⋅10⋅196+9⋅102+10=570+45+10=625= \sum_{m=1}^{9}(2m^2+m) + 10 = 2\cdot\frac{9\cdot10\cdot19}{6} + \frac{9\cdot10}{2} + 10 = 570 + 45 + 10 = 625.


The floor function's most important application in this thread: counting lattice points — integer coordinate points — under curves. That's where divisor counting and hyperbola geometry meet, in Counting Lattice Points.