BrainDen.com - Brain Teasers
• 0

# Massive multiplication

## Question

Hi there to all of you!

My friend proposed me this:

The result of 1.000.000 x 999.999 x 999.998 x 999.997 x ... 3 x 2 x 1

Tried with Excel, but I can't figure this out.

Any help is thanked!

## Recommended Posts

• 1

n factorial (represented as n!) is the product of all positive integers up to n.

So the number you are looking for is 1,000,000! ("one million factorial")

Spoiler

12! will fit in a 32 bit integer.  20! can fit in a 64 bit integer.  69! can still be represented by a scientific calculator with 2-digit decimal exponents.

A quick estimate of the number of digits would be on the order of 6,000,000.  (I simply took 1,000,000.  Saw it would add 6 digits to any number it is multiplied to. 1,000,000^1,000,000 would have 6,000,000 zeroes plus the leading one.  1,000,000 factorial would obviously have less digits than this.)  So a file holding the exact decimal expansion in ascii would be around a 6 megabyte file.

I was thinking I would try to estimate the answer using sterling's approximation.

I thought about determining the number of trailing 0's by figuring out the number of factors of 5 it would have.  (not too hard... floor(1,000,000/5) + floor(1,000,000/25) + floor(1,000,000/5^3) + ..., which would end up slightly less than 1,000,000/4 since 1/5 + 1/5^2 + 1/5^3 + ... = 1/4.  yay for sums of geometric series )

I thought maybe I'd post the answer as an exponential (e.g., e^some number or 10^some number).  This would make it easy as you could simply take the log (base e or 10) of each number up to 1,000,000 then add them all up.  1,000,000! would then be whatever base you chose to the power of the sum.  One advantage to using a base 10 logarithm would be that the integer part of the sum of the base 10 logs would be one less than the number of digits in the factorial.  The fractional part could then be used to try to figure out the leading digits of the answer (just take 10^(fractional part)).

I thought about posting c++ code to calculate it precisely.  I'd have an ever enlarging array of integers and have the multiplies cascade along it with overflows from the previous array entry. (I could still do this if you were supremely interested)

So to start, I decided to look up stirling's approximation on wikipedia's "factorial" page (which is where I took the above info on what factorials will fit in what representations).  The section just below sterling's approximation talked about computation of factorials.  So I thought I'd take a look for any hints for my code.  There it said wolfram alpha will calculate it up to 20,000,000.  So since I'm lazy, here's the answer from wolfram alpha. 8.26393168833124006237664610317266629113534797896387304516777588556337961103564508444653051131146397335160680421087858854146474695064783618230121097542329959011564174624917379888389269193414176545783239319872802472198939... × 10^5565708

```
So it is a 5565709 digit number.  They also give the number of trailing zeroes as 249998.```

Edited by EventHorizon
One wrong number
• 1

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account. ×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.