Woburn Challenge 1995

Problem 5: Factorial Power

The factorial of a whole number N (written "N!") is defined as follows: N! = 1 * 2 * 3 * ... * (N-1) * N

For example, 10! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 = 3628800.
The "factorial length" of a number N is defined as the number of digits in N!. Thus the factorial length of 10 is 7.


On each of five lines is a positive integer N in the range 1..500.


For each of the five inputs, output that number's factorial length in the format shown below.

Sample Input


Sample Output

The length of 1! is 1
The length of 2! is 1
The length of 5! is 3
The length of 10! is 7
The length of 52! is 68

All Submissions
Best Solutions

Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Sep 29, 2008

Languages Allowed:
C++03, PAS, C, ASM, C#, C++11

Comments (Search)

Does this problem use strings? Becuase i'm certain 500 factorial is way larger than the maximum integer in C++ or any other language (only worked with c++ and pascal so don't know)

Not necessarily, there is a simpler solution just needs a little bit of research.

My code works for the first 4 sample test cases but not for the 5th one.
What am I doing wrong...

You're overflowing the int you use to compute the factorial.

Would a long int work then?

500! has 1135 digits. In C++, a "long int" is the same as an "int", and they both hold up to 9 digits plus a little bit more.
Even a "long long int" only holds just over 18 digits. You won't be able to solve this by simply calculating the factorial.

I am learning c++ and I want to know if there is a length fuction in c++ which will give me the length of the number.


PS I tried to look for ir but it didn't help..:(

I doubt that the length function will help you on this problem

There's length of a string but think about how large the integer of 52! would be...

There is no length function for an integer (it can be done manually though, using a loop).

However, even the biggest type of integer in C++ can only store about 18 digits, while 52! has 68, so you'll need to think of another way.