Trailing Zeroes

Given that 13 ! = 13 × 12 × 11 × × 2 × 1 = 6227020800 13!= 13 \times 12 \times 11 \times \cdot \cdot \cdot \times 2 \times 1 = 6227020800 , it can be seen that 13 ! 13! contains two trailing zeroes.

How many trailing zeroes does 1000 ! 1000! contain?


The answer is 249.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

8 solutions

Chew-Seong Cheong
Nov 19, 2014

The Trailing Number of Zeros of n ! n! is given by:

z ( n ) = n 5 + n 5 2 + n 5 3 + n 5 4 + . . . \quad z(n) = \left\lfloor \space \dfrac {n}{5} \space \right\rfloor + \left\lfloor \space \dfrac {n}{5^2} \space \right\rfloor + \left\lfloor \space \dfrac {n}{5^3} \space \right\rfloor + \left\lfloor \space \dfrac {n}{5^4} \space \right\rfloor + ...

where \lfloor \space \rfloor is the greatest integer function.

For example, for 13 ! : z ( 13 ) = 13 5 = 2 13!: \quad z(13) = \lfloor \frac {13}{5} \rfloor = 2

This is because a trailing 0 is formed by a factor of 10 = 2 5 , 10=2\cdot 5, but there are always more 2's than 5's in the factorial, so we just need to count the number of powers of 5 in the product.

Similarly, for 1000 ! : 1000!:

z ( 1000 ) = 1000 5 + 1000 25 + 1000 125 + 1000 625 = 200 + 40 + 8 + 1 = 249 z(1000) = \lfloor \frac {1000}{5} \rfloor + \lfloor \frac {1000}{25} \rfloor + \lfloor \frac {1000}{125} \rfloor + \lfloor \frac {1000}{625} \rfloor = 200 + 40 + 8 + 1 = \boxed {249}

This should not have been a level 4 problem. @abdulrahman khaled

Anuj Shikarkhane - 6 years, 6 months ago

Log in to reply

It doesn't deserves level 4 must be a level 3, 2

Parth Lohomi - 6 years, 6 months ago

Now it's level 3 ,, it was a mistake

Abdulrahman El Shafei - 6 years, 6 months ago

Here Floor function is quiet similar to Box function. Right sir? I have used Box function to do it.

Sattik Biswas - 5 years, 2 months ago

Log in to reply

I thought the function was z(n)=sigma(i=1)k(2n/10^i)

Jeremy Davie - 3 years, 4 months ago

Log in to reply

It is likely that you will get the same answer. We need only to count the power of 5 which is equal to the power of 10. Because for every 5 there are three to four 2's.

Chew-Seong Cheong - 3 years, 4 months ago

I don't know if there is a box function. I think it is because some use [ ] [\cdot ] (for convenience) because the floor function symbol \lfloor \cdot \rfloor is not available to them.

Chew-Seong Cheong - 3 years, 4 months ago

Log in to reply

I hope that will be clear for you every time a number is multiplied by 10 an extra trailing zero is added, and as 10 = 2 times 5, we need only consider the number of factors of 5 present in 1000!; there are an abundance of factors of 2.

There are 1000/5=200 factors of 5, but we must also ensure that we take into account 25 = 5 times 5, which contains two factors of 5; hence there will be 1000/25=40 extra factors of 5. Similarly, 125 = 5 3 5^{3} , contains three factors of 5, and 625 = 5 4 5^{4} .

1000/5 = 200, 1000/25 = 40, 1000/125 = 8, and 1000/625 = 1.6.

Therefore, 1000! contains, 200 + 40 + 8 + 1 = 249 trailing zeroes.

Abdulrahman El Shafei - 6 years, 6 months ago

Log in to reply

Yes i did it this way only

sandeep Rathod - 6 years, 6 months ago

I figured this formula out. It's just the power of 5 in the prime factorisation of n! (every 5 will always find a 2 to buddy up with and make a 10), which come from the 5s within the numbers we multiply together: 1 for every multiple of 5, two for every multiple of 25, three for every multiple of 125, etc.

Davy Ker - 5 years, 2 months ago

Log in to reply

Yes, I realised the same thing when solving a similar earlier problem in Brilliant.org. You will discover more.

Chew-Seong Cheong - 5 years, 2 months ago
Arulx Z
Apr 1, 2016
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
n = int(raw_input())
c = 5

r = n // c

count = 0

while r > 0:
    count += r
    c *= 5
    r = n // c

print count

Keshav Ramesh
Jun 5, 2017

A special case of de Polignac's (or Legendre's) Formula for trailing zeroes gives us:

f ( n ) = i = 1 k n / 5 i = n / 5 + n / 5 2 + n / 5 3 + n / 5 4 + . . . + n / 5 k f(n)=\sum\limits_{i=1}^k \left \lfloor{n/5^i}\right \rfloor = \left \lfloor{n/5}\right \rfloor+\left \lfloor{n/5^2}\right \rfloor+\left \lfloor{n/5^3}\right \rfloor+\left \lfloor{n/5^4}\right \rfloor+...+\left \lfloor{n/5^k}\right \rfloor .

Plugging 1000 1000 in for n n , we have 200 + 40 + 8 + 1 = 249 200+40+8+1=249 , our final answer.

You round then to floor, right? Yet I don't get the same answer.

The Juk - 3 years ago

Interesting option.

Marijana Marinić-Kragić - 2 years, 12 months ago

We can simply let i = 1 1000 5 i \displaystyle\sum_{i=1}^{\infty} \bigg \lfloor \frac{1000}{5^i} \bigg \rfloor , since from some point all addends will be zero :)

Jacopo Piccione - 2 years, 10 months ago

Very simple solution:

To form a 0 you need a 2 and a 5 multiplied. It is obvious that there are more 5s than 2s, so the number of 0s is equal to the number of 5s.

  • Numbers that have 1 five: 1000/5 = 200
  • Number that have 2 fives: 1000/25 = 40
  • Number that have 3 fives: 1000/125 = 8
  • Number that have 4 fives: 1000/25 = 1

Number of 5s = Number of trailing 0s = 200 + 40 + 8 + 1 = 249 \boxed{249}

The proof of Legendre-de Polignac's formula (see Keshav solution) is based on this :)

Jacopo Piccione - 2 years, 10 months ago

There are more 2s than 5s but yes my process is the same

Sourjyo Deb - 2 years, 7 months ago

I believe you have a small mistake with your solution.

On your 4th row; "Numbers that have 4 fives" you list "1000/25", shouldn't you have listed "1000/625" as it is 1000/5^4.

Tony Valentine - 2 years, 6 months ago

(1000)! = 402387260077093773543702433923003985719374864210714632543799910429938512398629020592044208486969404800479988610197196058631666872994808558901323829669944590997424504087073759918823627727188732519779505950995276120874975462497043601418278094646496291056393887437886487337119181045825783647849977012476632889835955735432513185323958463075557409114262417474349347553428646576611667797396668820291207379143853719588249808126867838374559731746136085379534524221586593201928090878297308431392844403281231558611036976801357304216168747609675871348312025478589320767169132448426236131412508780208000261683151027341827977704784635868170164365024153691398281264810213092761244896359928705114964975419909342221566832572080821333186116811553615836546984046708975602900950537616475847728421889679646244945160765353408198901385442487984959953319101723355556602139450399736280750137837615307127761926849034352625200015888535147331611702103968175921510907788019393178114194545257223865541461062892187960223838971476088506276862967146674697562911234082439208160153780889893964518263243671616762179168909779911903754031274622289988005195444414282012187361745992642956581746628302955570299024324153181617210465832036786906117260158783520751516284225540265170483304226143974286933061690897968482590125458327168226458066526769958652682272807075781391858178889652208164348344825993266043367660176999612831860788386150279465955131156552036093988180612138558600301435694527224206344631797460594682573103790084024432438465657245014402821885252470935190620929023136493273497565513958720559654228749774011413346962715422845862377387538230483865688976461927383814900140767310446640259899490222221765904339901886018566526485061799702356193897017860040811889729918311021171229845901641921068884387121855646124960798722908519296819372388642614839657382291123125024186649353143970137428531926649875337218940694281434118520158014123344828015051399694290153483077644569099073152433278288269864602789864321139083506217095002597389863554277196742822248757586765752344220207573630569498825087968928162753848863396909959826280956121450994871701244516461260379029309120889086942028510640182154399457156805941872748998094254742173582401063677404595741785160829230135358081840096996372524230560855903700624271243416909004153690105933983835777939410970027753472000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

No. of trailing zeroes = 249

Dhruv Chitkara
Jan 28, 2018

The number of zeros can be written as a product of 2's and 5's Number of zeros = a ;where 'a' is (5*2)^a The exponent of 5 in 1000! is

1000/5 + 1000/25 + 1000/125 + 1000/625(rounds off to 1 )

= 200+40+8+1=249 Since 1000! Has more 2 exponents than 5 , the limiting number will be 5. Hence 1000! Will have 249 zeros Hope you found it easy:)

Yijun Zhou
Jan 3, 2019

I have no idea but use a C++ program to solve it. The sourse code is following.

include<iostream>

define MAX 100000

using namespace std; int main() { int n,a[MAX]; int i,j,k,count,temp; while(cin>>n) { a[0]=1; count=1; for(i=1;i<=n;i++) { k=0; for(j=0;j<count;j++) { temp=a[j]*i+k; a[j]=temp%10; k=temp/10;
} while(k) { a[count++]=k%10; k/=10; } } for(j=MAX-1;j>=0;j--)
if(a[j]) break; for(i=count-1;i>=0;i--) cout<<a[i]; cout<<endl; } return 0; } Then we count these trailing zeroes and the problem can be solve.

Adrian Pintea
Oct 22, 2018

More rudimentary form of Chew's solution. We know or observe that the trailing 0s are generated by multiples of 5 and only multiples of 5. Then: 1000 ! = X 5 1000 / 5 ( 1000 / 5 ) ! = X 5 200 200 ! 1000!=X*5^{1000/5}*(1000/5)!=X*5^{200}*200! , where X is the product of all numbers that don't divide by 5 We continue this method for the subsequent factorials: 1000 ! = X 5 200 200 ! = X Y 5 200 5 40 40 ! 1000!=X*5^{200}*200! =X*Y*5^{200}*5^{40}*40! 1000 ! = X 5 200 200 ! = X Y 5 200 5 40 40 ! = X Y Z 5 200 5 40 5 8 8 ! 1000!=X*5^{200}*200! =X*Y*5^{200}*5^{40}*40! =X*Y*Z*5^{200}*5^{40}*5^8*8! 1000 ! = X 5 200 200 ! = X Y 5 200 5 40 40 ! = X Y Z 5 200 5 40 5 8 8 ! = X Y Z W 5 200 5 40 5 8 5 1 1 ! 1000!=X*5^{200}*200! =X*Y*5^{200}*5^{40}*40! =X*Y*Z*5^{200}*5^{40}*5^8*8!=X*Y*Z*W*5^{200}*5^{40}*5^8*5^1*1! Finally you add the power of 5 and you get the number of trailing zeros: 200 + 40 + 8 + 1 = 249 200+40+8+1 = 249

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...