
To the Math enthusiasts here:
Is there a method of calculating the number of digits in 2222!
I have been asked by a student, and am not sure of how to arrive at this. Thanks.





Easy peasy. Stirling's approximation will give you the answer factorial to a few significant digits, and the decimal exponent exactly.
I'm sure you can do it from there...
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012





Thanks a lot. I didn't know about Stirling's formula.





Had to prove it in a uni calculus exam, ca 1965. I did then, but I don't think I could now.
Software rusts. Simon Stephenson, ca 1994. So does this signature. me, 2012





Actually you can "just do it", with a computer anyway. It's a big number, but not so big that a computer really struggles with it. It's fast enough to run it on those online code snippet running websites like ideone.






The answer is "one".
It's zero, I just checked:
int n = 2222;
int fact = 1;
for (int i = 1; i <= n; i++)
{
fact *= i;
}
OK, that's because it overflows 32 bits at i = 33, but it's close enough for government work!
"I have no idea what I did, but I'm taking full credit for it."  ThisOldTony
"Common sense is so rare these days, it should be classified as a super power"  Random Tshirt
AntiTwitter: @DalekDave is now a follower!





That's the reason for my asking the question.





"I have no idea what I did, but I'm taking full credit for it."  ThisOldTony
"Common sense is so rare these days, it should be classified as a super power"  Random Tshirt
AntiTwitter: @DalekDave is now a follower!





Reminds me of a "calculator" program I wrote back in the early 90s (it was a DOS program that supported stdin/stdout chaining) that treated numbers as strings and thus had no limit in what it could calculate. It supported the four basic operators plus exponent and factorial.
"One man's wage rise is another man's price increase."  Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it."  Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him."  James D. Miles





Builtin Win 10 calculator did it for me!





Didn't realize the built in Windows 10 calculator used the bigint library.





Me too. Didn't know that the Win10 calculator was so powerful.





It most likely uses some infinite precision library (I once wrote one, that is not the 'bigint' one!).
It could also sum log10 for all integer from 1 to 2022, take the antilog of the fractional part of the sum and the integer part as the Ennnn value. There is a small risk of roundoff errors, but even if you have a real need for calculating 2222! you rarely need the exact value to 6474 digits of precision.





Surely not. Type float/double can do it, see my message below.
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.





Amarnath S wrote: nd am not sure of how to arrive at this You make it homework.
Bastard Programmer from Hell
"If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics."  Some Bell.





Back of the napkin estimate: around 7000.
Reasoning: number of digits is given by log10. Stiriling formula mentioned by Peter says something like n!= O(n^n) (don't remember the whole formula and we are on the back of the napkin with no Google ). That makes number of digits 2222*log10(2222). The log is 3 and a bit (log10(1000) is 3 plus log10(2)). That puts the number of digits around 6666. Allowing for the lost factors in Stirling approximation, 7000 looks like a reasonable estimate.
EDIT: after the backofthenapkin estimate, I used the Win10 calculator to find the correct answer: 6473. Also rechecked the Stirling formula. Main reason for the difference is the 1/e^n factor that was missing in my estimate. Anyway a nice brain rinsing exercise
Mircea
modified 20Jan22 9:48am.





Really good estimate until you rounded it. According to the Windows 10 calculator, it's 3.4310637869208214326346682154289e+6473





Simple, you don't need integers, not even BigInteger. Try
double val = 1;
int pow10 = 0;
for (int i = 1; i <= 2222; i++) {
val *= i;
while (val > 10) {
val /= 10.0;
pow10++;
}
}
log("val=" + val + "; pow10=" + pow10);
you'll get
val=3.43106378692083; pow10=6473
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.





I bet you are a very good driver and always keep the vehicle well within the margins of the lane.
Great approach.





Nope, I use all lanes available, and then some.
Luc Pattyn [My Articles]
The Windows 11 "taskbar" is disgusting. It should be at the left of the screen, with real icons, with text, progress, etc. They downgraded my developer PC to a bloody iPhone.





using base #1, the factual of #2222 will take #222 hands and two feet.
«The mind is not a vessel to be filled but a fire to be kindled» Plutarch





So I ordered a package from Japan, some CD's (soundtracks that I can't buy in The Netherlands).
I just got a payment request from UPS, customs that I have to pay since last year I think, mainly implemented to stop people from buying cheap stuff from China.
The total fee is even more than the 21% VAT and I'm pretty sure that VAT was already included in the original price (but there's no way to check), but sure, I really have no other choice.
So I get an SMS, which I open on my phone, naturally, and follow the link in that text.
The following UPS page is not at all optimized for mobile viewing.
I have to put on my glasses, scroll left and right, zoom in and out, get a tiny finger transplant, you know the deal.
After finally filling out the form I get a message that IPPA is unavailable at this time, please try again later
Maybe UPS should spend some of its billions of profits from last year into making the page they send through SMS mobile friendly and making sure their services are available
For the money I'm paying I'd expect my package to be delivered in a golden carriage on a satin cushion, not this screw up





The collection fee being more than the import taxes has also happened in Canada, though it seems to have improved lately. And if they sent you an SMS, there's no excuse for not having a mobilefriendly website. But what really pisses me off are sites that assume that everyone has a smartphone for 2FA. My US and Canadian banks have enough sense to offer a passcode by voice. But GitHub, for one, is clueless.





Sounds like a classic mafia shakedown to me.



