Login | Register
Nerd ParadiseArtisanal tutorials since 1999

Ever notice how large factorials always end in a ton of zeros? If not, take a look at 999 Factorial (scroll all the way to the bottom). Lots of zeros!

Why is this so? Consider 15 factorial:

15! = 15 × 14 × 13 × 12 × 11 × 10 × 9 × 8 × 7 × 6 × 5 × 4 × 3 × 2 × 1

Obviously, there's at least 1 zero at the end of the final product, because you have a 10 thrown in there. However, you also have to consider that when you multiply 5 and 2 together, you'll also get another 10 in there. That means at least 2 zeros in the final product. Last, but not least, there's also that 15. When you multiply that 15 by an even number (4 for example), you'll get another multiple of 10.

The final product is 1307674368000. 3 zeros thanks to our 5, 10, and 15. Notice the pattern? For every multiple of 5 in your list of numbers, you add a zero. Does this mean 100! ends with 20 zeros?

100! = 93326blahblahblahblah0916864000000000000000000000000

24 zeros. Where did the extra 4 come from?

You also have to consider that some of the numbers you are multiplying contain a factor of 5 multiple times. 25, 50, 75, and 100 all have factors of 5 twice. So for each multiple of 25, you need to add 1 more zero. If the number we were calculating were larger, we'd also have to consider factors of 125 which have 3 factors of 5.

Notice we're not considering the multiples of 2 needed to multiply these 5's to make them 10's. That's because there are far more multiples of 2's in any given factorial than 5's.

How many 0's does 879! end with?

First we count how many numbers between 1 and 879 have at least 1 factor of 5 in them.

879 / 5 = 175.8

There are 175 numbers that have a factor of 5 in them. That means our factorial will have at least 175 zeros.

Now we count up how many numbers between 1 and 879 have at least 2 factors of 5 in them.

879 / 25 = 35.16

There are 35 numbers that have at least two factors of 5 in them. That means the factorial will end with at least 175 + 35 zeros.

Count how many numbers have at least 3 factors of 5...

879 / 125 = 7.032

879! ends in at least 175 + 35 + 7 zeros

Now count how many factors have 5 in them 4 times.

879 / 625 = 1.4064

879! ends in 175 + 35 + 7 + 1 zeros

We don't need to check any further, because 625 * 5 is larger than the number we're factorialing. Therefore your final answer is 218 zeros.

Let's check our work...

879! = 
7807233019 1554549656 8822717391 8496468070 7507748996 0813492397 
2526949223 3381995549 8133963142 5829715464 2166031710 4985392271 
8851963397 0474264206 5389635993 5286963902 8862715976 7542577436 
7636420532 7401092380 8749716987 5302684162 3019854640 9293314024 
4511806802 3808832307 6645891644 7501514474 5609100456 7174437604 
2283652700 6607845736 3439753378 6328791870 0384190599 6151004100 
5477233862 3268489362 6248858094 7550975430 3698213193 0931186304 
8114404811 8421058219 5584516776 5819064356 5304685260 1213198893 
1456621846 7819142898 4014618126 8400274680 5435476607 7892196180 
4227583291 6635167933 3682523565 4828989835 2709791672 2246056288 
1595624523 3603289500 9342000449 3813021847 9308479842 2405210023 
9678911682 6841575647 8452822796 6601140228 4484233078 1804126798 
9823018175 4236812822 8507070156 3352854071 8519744472 0357238012 
4381718006 2500419750 9841920651 3047806813 9438335527 4898270918 
6248319566 0862377750 9908379376 3704514408 2896275343 5224890415 
0532062634 4740675555 4301515639 9216717768 7426246425 1263405575 
8337449073 7225071243 0559972595 0337185007 4451940095 2067437481 
0645581830 3679592992 0630010699 6863357836 9252477883 1918507637 
9113598499 7349791080 1908352597 5859073385 1566578576 7570567262 
8210590523 6382060960 2447953037 0721428389 7762235940 5724563749 
6550474210 3271397205 8675756103 1690890736 4725501943 4708237000 
3604820512 2717953496 1947236409 8201029917 6358217030 6582502635 
5265255974 7505236220 8217979185 0542081579 2795665404 0069814182 
5177727217 6171463038 7206398810 5175536207 3261783255 9121817271 
2072561989 0121999367 2991193551 1892264406 4045936746 2809626164 
2656823522 2190076925 1782330900 6213440295 0349449927 0075099729 
1337561234 1885529151 8009423803 4929343661 4385845250 4435317255 
8282379392 0048903099 3395578489 6672562174 5797556692 2542030360 
1661967769 0434258143 3838663981 4655847741 8903685953 6067239055 
3721686778 2285891550 0723469639 8788200795 9021143357 5904000171 
6376713647 4941381905 2027190414 0447658627 6969402559 4691918781 
6734087426 7970668210 4503047426 1399029598 4135744365 3945868172 
4664768724 2315097167 7736527894 0657050564 3813377742 9628295103 
7308895232 0000000000 0000000000 0000000000 0000000000 0000000000 
0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 
0000000000 0000000000 0000000000 0000000000 0000000000 0000000000 
0000000000 0000000000 0000000000 0000000000 00000000