x!, as you know, would be x * (x-1) * (x-2) * ... * 3 * 2 * 1.
Obviously we don't want to calculate x! and count the digits if it would be a very large number.
For example, calculating 1000! isn't a very effective way to get the number of digits.
Logarithmic rules can be applied in these situations.
log(ab) = log(a) + log(b)
And we want to calculate log(1000!) before calculating 1000! first.
log(1000!) = log(1000) + log(999) + log(998) + log(997) + ... + log(3) + log(2) + log(1)
Still 1000 numbers to add, but much easier than trying to multiply 1000 numbers together.
With a little bit of calculation, we find the answer 2567.60464422213, which means after multiplying numbers 1 to 1000, we will get a 2568-digit number
Thursday, September 20, 2007
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment