If we have a number like 92928212819319231923192312313212312 (means the size can be any thing) so how can i find the last non-zero number in its factorial. Using STL i wanna to get solved this problem...............
I don't understand the question. No number has a factorial of zero except zero.
And computing the factorial of a number like the one you posted would require more memory and time than all the computers on the earth from its creation until it is swallowed by the sun.
Figure 1 The ultimate laptop. The ‘ultimate laptop’ is a computer with a mass of 1 kg and a volume of 1 l, operating at the fundamental limits of speed and memory capacity fixed by physics. The ultimate laptop performs 2*mc^2/pi<weird symbol> = 5.4258*10^50 logical operations per second on ~10^31 bits. Although its computational machinery is in fact in a highly specified physical state with zero entropy, while it performs a computation that uses all its resources of energy and memory space it appears to an outside observer to be in a thermal state at ~10^9 degrees Kelvin. The ultimate laptop looks like a small piece of the Big Bang.
It also says that a bit takes 10^9 seconds to travel from one end of the computer to the other (~31.69 years).
Suppose I have a number 5
factorial of this number is 120
the last non-zero number in the factorial of 5 is 2.
so if i want to get the last non-zero number in the factorial of the number 9239012119318902831932 (means a number which can have any number of digits). I want to solve this problem using C++ STL.
Google "c++ bignum" for arbitrary-precision number libraries. There are a few good ones.
And you still won't be able to generate the factorial of such a large number in your lifetime. But I'm starting to think that by "factoral" you mean digit. int main has it exactly right. Good luck!
There may well be an algorithm that exists that can do this. I haven't searched the 'net, but I have given it some thought.
For example, 5! = 5 * 4 * 3 * 2 * 1. Since 5 * 2 = 10, it follows that for all integers N >= 5, N! can
be written in the form N! = x * 10^k, where x % 10 != 0 and x % 10 is what you are looking for.
Since 5! contains factors 2 and 5 (which yield one zero) and since 10! contains factors 2, 5, and 10 (which yield two zeroes), I think k = trunc( N / 5 ). Further, given a and b such that at least one of the two is even, then ab is even. Since 4 is even and since 4 does not combine with another integer < 10 to form a product evenly divisble by 10 (2 and 5 are already used), it follows that in the formula N! = x * 10^k, x must be even (and non-zero). Which means that x must be 2, 4, 6, or 8.
Not sure if this helps at all. Sounds like an interesting problem.