r/dailyprogrammer • u/oskar_s • Jul 16 '12
[7/16/2012] Challenge #77 [intermediate] (Last digit of factorial)
The factorial of 10 is 3628800. The last non-zero digit of that factorial is 8.
Similarly, the last non-zero digit of the factorial of 103 is 2.
Compute the last non-zero digit of the factorial of 109 .
Bonus: Compute the last non-zero digit of the factorial of 10100 .
- Thanks to ashashwat for suggesting this problem at /r/dailyprogrammer_ideas! If you have a problem that you think would be good for us, why not head over there and suggest it?
12
Upvotes
6
u/skeeto -9 8 Jul 16 '12 edited Jul 16 '12
My own code but not my own algorithm.
All results are instantaneous, including bonus:
2
u/zefyear Jul 17 '12
Deal with it :)
You could iterate from the final index of the element if you'd like and that would be more efficient than gsub but I just thought showing off Stieltjes transformation would be rad.
1
u/Cosmologicon 2 3 Jul 16 '12 edited Jul 16 '12
Non-bonus python version, takes a few minutes to run:
1
u/Acebulf Jul 16 '12 edited Jul 16 '12
As a beginner programmer this is what I used:
1
u/fridgeridoo Jul 17 '12
Absolutely no idea how to approach this :/
1
u/02471 Jul 17 '12 edited Jul 17 '12
In C
On a side note, this is quite similar to this problem from Project Euler.
0
u/Scroph 0 0 Jul 16 '12
Not sure if people are still looking for a smart way to solve this, or if their programs are still computing...
I'll edit this
whenif I find the solution.0
u/IAMABananaAMAA Jul 16 '12
VB.NET has an OverFlowException :. I don't feel like rewriting my large-number multiplication function. Sorry :(