HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →
Live examsInternational live exams are comingTell us which exam you want first. Timed practice papers are open now.See what is coming →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Space Science and Astronomy
  • Earth and Environmental Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Factorials, Irrational Numbers, Digits and the Floor Function
  1. 1The floor function and Legendre's formula
  2. 2Rational and irrational numbers
  3. 3Digits, bases, squares and cubes
  1. Mathematics
  2. /Factorials, Irrational Numbers, Digits and the Floor Function
  3. /The floor function and Legendre's formula

Course 27.3·Lesson 1 of 3

The floor function and Legendre's formula

The floor ⌊x⌋\lfloor x \rfloor⌊x⌋ is the largest integer not above xxx, and {x}=x−⌊x⌋\{x\} = x - \lfloor x \rfloor{x}=x−⌊x⌋

Lesson 1 of 3Show all lessonsHide
Factorials, Irrational Numbers, Digits and the Floor Function
  1. 1The floor function and Legendre's formula
  2. 2Rational and irrational numbers
  3. 3Digits, bases, squares and cubes

Try the code and the simulations beside the lesson.

What you will be able to do

  • work with the floor function and the fractional part, also for negative numbers;
  • count multiples with ⌊n/d⌋\lfloor n/d \rfloor⌊n/d⌋;
  • prove Legendre's formula and use it for the zeros at the end of n!n!n! and for powers of primes in binomial coefficients.

Rounding down

A lift can carry 888 people. How many full trips does it make for 595959 people? It makes 777, because 59÷8=7.37559 \div 8 = 7.37559÷8=7.375, and we drop the part after the point. That is rounding down.

The floor function

The floor of a real number xxx, written ⌊x⌋\lfloor x \rfloor⌊x⌋, is the largest integer that is not above xxx. Many Indian books call it the greatest integer function and write [x][x][x]. The notation ⌊x⌋\lfloor x \rfloor⌊x⌋ is used in most olympiad and university books.

  • ⌊3.7⌋=3\lfloor 3.7 \rfloor = 3⌊3.7⌋=3 and ⌊5⌋=5\lfloor 5 \rfloor = 5⌊5⌋=5.
  • ⌊−3.7⌋=−4\lfloor -3.7 \rfloor = -4⌊−3.7⌋=−4, not −3-3−3. The floor goes down the number line, to the left.

The fractional part is {x}=x−⌊x⌋\{x\} = x - \lfloor x \rfloor{x}=x−⌊x⌋, and it always satisfies 0≤{x}<10 \le \{x\} < 10≤{x}<1. So {−3.7}=0.3\{-3.7\} = 0.3{−3.7}=0.3. The ceiling ⌈x⌉\lceil x \rceil⌈x⌉ rounds up.

The definition gives one useful inequality:

⌊x⌋≤x<⌊x⌋+1.\displaystyle \lfloor x \rfloor \le x < \lfloor x \rfloor + 1.⌊x⌋≤x<⌊x⌋+1.

Rules of the floor

  1. ⌊x+n⌋=⌊x⌋+n\lfloor x + n \rfloor = \lfloor x \rfloor + n⌊x+n⌋=⌊x⌋+n for every integer nnn.
  2. ⌊x⌋+⌊y⌋≤⌊x+y⌋≤⌊x⌋+⌊y⌋+1\lfloor x \rfloor + \lfloor y \rfloor \le \lfloor x + y \rfloor \le \lfloor x \rfloor + \lfloor y \rfloor + 1⌊x⌋+⌊y⌋≤⌊x+y⌋≤⌊x⌋+⌊y⌋+1.
  3. ⌊−x⌋=−⌊x⌋−1\lfloor -x \rfloor = -\lfloor x \rfloor - 1⌊−x⌋=−⌊x⌋−1 when xxx is not an integer.
  4. ⌊⌊x⌋n⌋=⌊xn⌋\left\lfloor \dfrac{\lfloor x \rfloor}{n} \right\rfloor = \left\lfloor \dfrac{x}{n} \right\rfloor⌊n⌊x⌋​⌋=⌊nx​⌋ for a positive integer nnn.
  5. Counting multiples. From 111 to nnn there are ⌊nd⌋\left\lfloor \dfrac{n}{d} \right\rfloor⌊dn​⌋ multiples of ddd.

Rule 5 links the floor to the division algorithm. If n=dq+rn = dq + rn=dq+r with 0≤r<d0 \le r < d0≤r<d, then ⌊n/d⌋=q\lfloor n/d \rfloor = q⌊n/d⌋=q, and the multiples are d,2d,…,qdd, 2d, \dots, qdd,2d,…,qd.

Hermite's identity. For every real xxx, ⌊x⌋+⌊x+12⌋=⌊2x⌋\lfloor x \rfloor + \left\lfloor x + \tfrac{1}{2} \right\rfloor = \lfloor 2x \rfloor⌊x⌋+⌊x+21​⌋=⌊2x⌋. Check it by splitting into {x}<12\{x\} < \tfrac{1}{2}{x}<21​ and {x}≥12\{x\} \ge \tfrac{1}{2}{x}≥21​.

Solving an equation with a floor

Solve ⌊x⌋=2x−3\lfloor x \rfloor = 2x - 3⌊x⌋=2x−3.

  1. Name the floor. Let n=⌊x⌋n = \lfloor x \rfloorn=⌊x⌋, an integer. Then x=n+32x = \dfrac{n + 3}{2}x=2n+3​.
  2. Use the inequality. n≤n+32<n+1n \le \dfrac{n + 3}{2} < n + 1n≤2n+3​<n+1. The left part gives n≤3n \le 3n≤3, and the right part gives n>1n > 1n>1.
  3. Read off. n=2n = 2n=2 or n=3n = 3n=3, so x=2.5x = 2.5x=2.5 or x=3x = 3x=3.
  4. Check. ⌊2.5⌋=2=2×2.5−3\lfloor 2.5 \rfloor = 2 = 2 \times 2.5 - 3⌊2.5⌋=2=2×2.5−3 and ⌊3⌋=3=2×3−3\lfloor 3 \rfloor = 3 = 2 \times 3 - 3⌊3⌋=3=2×3−3.

The trick is always the same: give the floor a name, then squeeze it with the inequality.

Legendre's formula

How many times does 222 divide 10!=1×2×⋯×1010! = 1 \times 2 \times \dots \times 1010!=1×2×⋯×10? Count the factors 222 in each number. The even numbers 2,4,6,8,102, 4, 6, 8, 102,4,6,8,10 give one each: that is ⌊10/2⌋=5\lfloor 10/2 \rfloor = 5⌊10/2⌋=5. The multiples of 444, which are 444 and 888, give a second one: ⌊10/4⌋=2\lfloor 10/4 \rfloor = 2⌊10/4⌋=2. The multiple of 888 gives a third: ⌊10/8⌋=1\lfloor 10/8 \rfloor = 1⌊10/8⌋=1. In all, 5+2+1=85 + 2 + 1 = 85+2+1=8.

Legendre's formula. For a prime ppp, the exponent of ppp in n!n!n! is

⌊np⌋+⌊np2⌋+⌊np3⌋+⋯\displaystyle \left\lfloor \frac{n}{p} \right\rfloor + \left\lfloor \frac{n}{p^2} \right\rfloor + \left\lfloor \frac{n}{p^3} \right\rfloor + \cdots⌊pn​⌋+⌊p2n​⌋+⌊p3n​⌋+⋯

The sum stops by itself once pk>np^k > npk>n.

Proof. A number m≤nm \le nm≤n with exactly jjj factors ppp is a multiple of p,p2,…,pjp, p^2, \dots, p^jp,p2,…,pj, and of no higher power. So it is counted once in each of the first jjj terms: jjj times in all. Adding over all mmm gives the total number of factors ppp in n!n!n!. Proof complete.

The zeros at the end of n factorial

A zero at the end of a number is a factor 10=2×510 = 2 \times 510=2×5. In n!n!n! there are many more factors 222 than factors 555, so the number of zeros is the exponent of 555. For 100!100!100!:

⌊1005⌋+⌊10025⌋=20+4=24.\displaystyle \left\lfloor \frac{100}{5} \right\rfloor + \left\lfloor \frac{100}{25} \right\rfloor = 20 + 4 = 24.⌊5100​⌋+⌊25100​⌋=20+4=24.

So 100!100!100! ends in 242424 zeros.

![A table of the numbers 1 to 25 in five rows of five, standing for the factors of 25 factorial. Every multiple of 5 (5, 10, 15, 20, 25) has one orange dot, and 25 has a second dot because 25 = 5 times 5. A caption reads: 25 divided by 5 gives 5 dots in the first round, 25 divided by 25 gives 1 more, so 25 factorial has 6 factors 5 and ends in 6 zeros.](https://tuygolavdykfydmasiqc.supabase.co/storage/v1/object/public/discussion-images/57b80fd5-0d05-40b0-bb7c-fdadd190c00d/figures/ch27-number-theory-divisibility-and-primes/nt-n3-legendre.png) The multiples of 252525 give a second 555 each, which is why the count jumps by two at 25!25!25!: 24!24!24! ends in 444 zeros and 25!25!25! in 666. So no factorial ends in exactly 555 zeros.

There is a second form of the formula. If sp(n)s_p(n)sp​(n) is the sum of the digits of nnn in base ppp, the exponent is n−sp(n)p−1\dfrac{n - s_p(n)}{p - 1}p−1n−sp​(n)​. For p=2p = 2p=2 and n=100n = 100n=100, written 110010011001001100100 in base 222, it gives 100−31=97\dfrac{100 - 3}{1} = 971100−3​=97.

Primes in binomial coefficients

Since (2nn)=(2n)!n! n!\dbinom{2n}{n} = \dfrac{(2n)!}{n!\,n!}(n2n​)=n!n!(2n)!​, the exponent of ppp in it is the exponent in (2n)!(2n)!(2n)! minus twice the exponent in n!n!n!. For example, the exponent of 333 in (3015)\dbinom{30}{15}(1530​) is (10+3+1)−2(5+1)=2(10 + 3 + 1) - 2(5 + 1) = 2(10+3+1)−2(5+1)=2. The German mathematician Ernst Kummer showed that this exponent is the number of carries when you add n+nn + nn+n in base ppp.

Practise with new numbers

Try it in Python

The program finds the exponent of a prime in n!n!n! in two ways and counts the zeros of 100!100!100! from its digits.

Read it first. Then run it. Do the three ways agree?

1. Change 100 to 1000 in the last part. How many zeros does 1000!1000!1000! end in? Predict with the formula first.

2. Use legendre to find the exponent of 777 in 1000!1000!1000!.

Common mistakes

  • The floor of a negative number. ⌊−2.3⌋=−3\lfloor -2.3 \rfloor = -3⌊−2.3⌋=−3.
  • Stopping Legendre's sum after one term. Multiples of p2p^2p2, p3p^3p3, ... add more.
  • Counting the factors 2 for the zeros. The factors 555 are fewer, so they decide.
  • Thinking every number of zeros is possible. Some counts are skipped, at each multiple of 252525.

Remember these

  • ⌊x⌋≤x<⌊x⌋+1\lfloor x \rfloor \le x < \lfloor x \rfloor + 1⌊x⌋≤x<⌊x⌋+1, and {x}=x−⌊x⌋\{x\} = x - \lfloor x \rfloor{x}=x−⌊x⌋.
  • From 111 to nnn there are ⌊n/d⌋\lfloor n/d \rfloor⌊n/d⌋ multiples of ddd.
  • Exponent of ppp in n!n!n!: ⌊n/p⌋+⌊n/p2⌋+…\lfloor n/p \rfloor + \lfloor n/p^2 \rfloor + \dots⌊n/p⌋+⌊n/p2⌋+…
  • Zeros at the end of n!n!n!: the exponent of 555.
  • Exponent of ppp in (2nn)\binom{2n}{n}(n2n​): the exponent in (2n)!(2n)!(2n)! minus twice that in n!n!n!.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Find ⌊−4.2⌋\lfloor -4.2 \rfloor⌊−4.2⌋, ⌈−4.2⌉\lceil -4.2 \rceil⌈−4.2⌉ and {−4.2}\{-4.2\}{−4.2}.
  1. How many zeros are at the end of 60!60!60!?
  1. Find the exponent of 333 in 30!30!30!.
  1. How many whole numbers from 111 to 700700700 are multiples of 777 but not of 494949?
  1. Solve ⌊2x⌋=5\lfloor 2x \rfloor = 5⌊2x⌋=5.

References

  • David M. Burton, Elementary Number Theory, Chapter 6, section 6.3 on the greatest integer function and Legendre's formula.
  • Ivan Niven, Herbert S. Zuckerman and Hugh L. Montgomery, An Introduction to the Theory of Numbers, Chapter 4, section 4.1 on the greatest integer function.

Enroll free in Factorials, Irrational Numbers, Digits and the Floor Function

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

A calculator shows only the first digits of a huge factorial, but you can still count the zeros at…Hard · High School (11–12) · by StemPy Lab
The number (100, 50) = (100!)/(50! 50!) has 30 digits…Advanced · High School (11–12) · by StemPy Lab
Prove Hermite's identity lfloor x rfloor + lfloor x + 1/2 rfloor = lfloor 2x rfloor for every real…Advanced · High School (11–12) · by StemPy Lab
Next: lesson 2Rational and irrational numbers
← Factorials, Irrational Numbers, Digits and the Floor Function
← PreviousRational and irrational numbers →

Discussion (0)

Log in to join the discussion.

Loading…

is the fractional part. The number of multiples of
ddd
from
111
to
nnn
is
⌊n/d⌋\lfloor n/d \rfloor⌊n/d⌋
. Legendre's formula counts the exponent of a prime
ppp
in
n!n!n!
as
⌊n/p⌋+⌊n/p2⌋+…\lfloor n/p \rfloor + \lfloor n/p^2 \rfloor + \dots⌊n/p⌋+⌊n/p2⌋+…
, and with
p=5p = 5p=5
it counts the zeros at the end of
n!n!n!
.
about 25 min1 simulation1 practice question1 Python program5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.

Python Labs (1)

Legendre's formula by machinePython Lab · by StemPy Lab