Interactive · 2 questions

Factorials can be put to many uses. Most of this, however, is used in probability, which we will not discuss in this topic. However, there are certain commonly tested aspects of pure-algebraic factorials that you should know.

How many consecutive zeros are in the end of 300!300!?

Choose one answer

Preparing for a math contest?

Working through past problems on one idea at a time is one of the most effective ways to prepare. These are real problems from the AMC 8, AMC 12 and AIME, the national math competitions for middle and high school students, each with a worked solution on LIVE by Po-Shen Loh.

Read · 2 min

Legendre's Formula

Before I start, I assume that everyone looking this post understand what are floor function, Euclidean algorithm and number bases.

In some mathematics competition, you are required to do big operations with limited of time, as an example, what is the highest power of kk that divides n!n! ? This is pretty popular and most students may get stumped when they see this type of problem. How do we tackle this type of problem?

We have one simple formula, that is Legendre's Formula. It states that

ep(n!)=∑i=1∞⌊npi⌋=n−Sp(n)p−1e_p(n!)=\displaystyle\sum^{\infty}_{i=1}\Big\lfloor\frac{n}{p^i}\Big\rfloor=\frac{n-S_p(n)}{p-1}

where pp is a prime, ep(n)e_p(n) is the exponent of pp in factorisation of nn, SpS_p is the sum of digits of nn when written in base pp.

For proofs, see this link. Credits to AoPS.

Now we are going to move on to some examples to make you clear.

  1. Find the highest power of 2 that divides 15!.

Solution. This is a direct application of Legendre's Formula, we have

e2(15!)=∑i=1∞⌊152i⌋=15−S2(15)2−1e_2(15!)=\displaystyle\sum^{\infty}_{i=1}\Big\lfloor\frac{15}{2^i}\Big\rfloor=\frac{15-S_2(15)}{2-1}

You can either choose the middle of the equality or the rightmost of the equality to calculate. In fact, do one of them is enough.

e2(15!)=⌊152⌋+⌊1522⌋+⌊1523⌋+⌊1524⌋+...=11e_2(15!)=\Big\lfloor\frac{15}{2}\Big\rfloor+\Big\lfloor\frac{15}{2^2}\Big\rfloor+\Big\lfloor\frac{15}{2^3}\Big\rfloor+\Big\lfloor\frac{15}{2^4}\Big\rfloor+...=11

OR

e2(15!)=15−S2(15)2−1e_2(15!)=\frac{15-S_2(15)}{2-1}

Here, we need to change 15 into binary aka base 2. It is simple, use Euclidean algorithm.

15=2(7)+115=2(7)+1

7=2(3)+17=2(3)+1

3=2(1)+13=2(1)+1

1=2(0)+11=2(0)+1

Take the remainders, which are 1, 1, 1, 1. Read it from bottom to top, that is 15 in base 2! Therefore, 15=(1111)215=(1111)_2, S2(15)=4S_2(15)=4. Substitute back, we get our final answer which is 11.

(They lead to same answer, but this is not strong enough to prove the formula above. This is just to show you how do you tackle the similar problems in the future.)

  1. Find the highest power of 10 that divides 23!.

(For the next problems, I will show the calculation in the middle part of equality.)

Analysis: When you see the question asks you to find the highest power of yy that divides x!x! and yy is composite, take the largest prime factor of yy. So, for this problem, the highest prime factor of 10 is 5. Set your n=23n=23 and p=5p=5 (Remember the formula above?).

Solution: e5(23!)=⌊235⌋+⌊2352⌋+...=4e_5(23!)=\Big\lfloor\frac{23}{5}\Big\rfloor+\Big\lfloor\frac{23}{5^2}\Big\rfloor+...=4

  1. Find the highest power of 27 that divides 27!.

Analysis: Notice that 27 is a perfect power of 3. Same as above, take the largest prime factor, which is 3 and set your pp as 3. Remember in the end of your solution you must divide it by 3 and take the integral part of your answer. As an example, if you get 8238\frac{2}{3}, then your answer should be 8.

[Notice that they ask for the highest power of 27, and 2723=927^{\frac{2}{3}}=9 (recall the multiplication of indices formula, am×an=am+na^m\times a^n=a^{m+n})]

Solution: e3(27!)=⌊273⌋+⌊2732⌋+⌊2733⌋+⌊2734⌋+...=13e_3(27!)=\Big\lfloor\frac{27}{3}\Big\rfloor+\Big\lfloor\frac{27}{3^2}\Big\rfloor+\Big\lfloor\frac{27}{3^3}\Big\rfloor+\Big\lfloor\frac{27}{3^4}\Big\rfloor+...=13

So the highest power of 27 that divides 27! is ⌊133⌋=4\Big\lfloor\frac{13}{3}\Big\rfloor=4.

  1. Find the highest power of 64 that divides 128!

Analysis: Follow all the steps as in problems 1,2 and 3, and this time you have to divide by 6 in the end. Do you see why?

Solution: e2(128!)=⌊1282⌋+⌊12822⌋+⌊12823⌋+⌊12824⌋+...=127e_2(128!)=\Big\lfloor\frac{128}{2}\Big\rfloor+\Big\lfloor\frac{128}{2^2}\Big\rfloor+\Big\lfloor\frac{128}{2^3}\Big\rfloor+\Big\lfloor\frac{128}{2^4}\Big\rfloor+...=127

So the highest power of 64 that divides 128! is simply ⌊1276⌋=21\Big\lfloor\frac{127}{6}\Big\rfloor=21.

Time for some practices!!!

5)Find the maximum value of nn in an∣k!a^n|k! when

i) a=2, k=425

ii) a=6, k=253

iii) a=12, k=423

That's all. :)

Read · 2 min

Prime Factorization of Factorials

The reader should read this post for some introduction to floor functions and preliminary problems.

Let's start with a classic problem.

Find the number of zeros at the end of 2015!2015!

If you don't know what factorial is, read What is a factorial. Then, experiment with some small values of the factorials - n!n! has no zeros for n=0,1,2,3,4n=0,1,2,3,4, and 5!5! has a zero at the end for the first time. So, let's explore when a number has trailing zeros. This is kinda easy. A number has trailing zeros when it is divisible by 1010. More precisely, if nn is divisible by 10k10^k, then it has kk trailing zeros. For example, 13001300 is divisible by 10210^2, and is has two trailing zeros. So, to find the number of trailing zeros of n!n!, we just need to find the maximum power kk for which 10k10^k divides n!n!. In other words, we should investigate the prime factorization of factorials.

5!=23⋅31⋅515!=2^3\cdot3^1\cdot5^1 and 6!=24⋅32⋅516!=2^4\cdot3^2\cdot5^1. It is obvious that there are more 22's than 55's. Therefore, if we count the number of 55 in n!n!, that will be the number of trailing zeros as well. Because each 55 paired with a 22 will give us a 1010, and the 22's not paired will be left alone. See the demonstration with n=5,6n=5,6 and some other values. You will reach the same conclusion.

Now, we focus only on how to get the number of 55's in n!n!. First, ask yourself, when do we get a 55? We don't get any in 1,2,3,41,2,3,4, but in 55. So, first there is a 55 in 5!5!. So, each number divisible by 55 contributes some factors of 55 in the factorization. Let's take 28!28! for example. We will get a 55 from 5,10,15,20,255,10,15,20,25 up to 2828. Each of them gives at least one 55. So, the power of 55 in 28!28! is 55 at least. In short, this is actually the number of numbers divisible by 55 which are less than or equal to 2828, which is in turn ⌊285⌋=5\left\lfloor\frac{28}5\right\rfloor=5.

But, there were some extra 55's. The extra 55 actually comes from 2525, since it is divisible by 525^2. Which means, each number divisible by 525^2 will give an extra 55. The number of such numbers is ⌊2825⌋=1\left\lfloor\frac{28}{25}\right\rfloor=1. Thus, the maximum power of 55 in 28!28! is ⌊285⌋+⌊2825⌋=5+1=6\left\lfloor\frac{28}5\right\rfloor+\left\lfloor\frac{28}{25}\right\rfloor=5+1=6. We don't need to go see if any number is divisible by 53=1255^3=125 since 125>28125>28.

Similarly, for 143!143!, it would be ⌊1435⌋+⌊14352⌋+⌊14353⌋=28+5+1=34\left\lfloor\frac{143}{5}\right\rfloor+\left\lfloor\frac{143}{5^2}\right\rfloor+\left\lfloor\frac{143}{5^3}\right\rfloor=28+5+1=34. Therefore, the number of trailing zeros of n!n! is \begin{eqnarray*} \left\lfloor\frac{n}{5^1}\right\rfloor+ \left\lfloor\frac{n}{5^2}\right\rfloor+\ldots+ \left\lfloor\frac{n}{5^k}\right\rfloor \end{eqnarray*} where kk is such that 5k≤n<5k+15^k\le n<5^{k+1}. For n=143n=143, we had k=3k=3, as 53≤143<545^3\le 143<5^4. However, it is equally correct to just write this as \begin{eqnarray*} \left\lfloor\frac{n}{5^1}\right\rfloor+ \left\lfloor\frac{n}{5^2}\right\rfloor+ \left\lfloor\frac{n}{5^3}\right\rfloor+\ldots\infty \end{eqnarray*} because the terms ⌊n5i⌋\left\lfloor\frac{n}{5^i}\right\rfloor become zero for i>ki>k. Using summation, this is ∑i≥1⌊n5i⌋\sum\limits_{i\geq1}\left\lfloor\frac{n}{5^i}\right\rfloor or, ∑i=1k⌊n5i⌋\sum\limits_{i=1}^k\left\lfloor\frac{n}{5^i}\right\rfloor where kk is the largest integer such that 5k≤n5^k\leq n i.e. 5k≤n<5k+15^k\leq n<5^{k+1}. Using logarithms, we may write k=⌊log⁡5n⌋k=\lfloor \log_5 n\rfloor.

Certainly, the same process works for any prime pp. The maximum power of pp in n!n! is therefore \begin{eqnarray*} \left\lfloor\frac{n}{p^1}\right\rfloor+ \left\lfloor\frac{n}{p^2}\right\rfloor+ \left\lfloor\frac{n}{p^3}\right\rfloor+\ldots & = & \sum\limits_{i=1}^{\lfloor \log_p n \rfloor}\left\lfloor\frac{n}{p^i}\right\rfloor \end{eqnarray*} This is known as Legendre's theorem.

Type a concept, like “slope” or “photosynthesis”.

↑ ↓ to choose · Enter to openSearch explanations and problems