Evaluating 993!

How many digits are there in 993!?


The answer is 2547.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

8 solutions

Shaun Loong
Apr 22, 2014

To solve this question without computer programming, we take the logarithm of 993 factorial. Since the number of digits of x x can be calculated using the formula d = y + 1 d=\lceil y \rceil+1 , where d d is the number of digits of x x and y = log 10 x y=\log_{10}x . log 10 993 ! = n = 1 993 log 10 n = 2546.613... \log_{10}993!=\sum_{n=1}^{993}\log_{10}n=2546.613...

\therefore number of digits in 993 ! 993! is 2546 + 1 = 2547 2546+1=\boxed{2547} .

Technically, aren't you using computing to find what log 10 n \sum \log_{10} n is?

You can approximate it by using integration, to evaluate it as 1 994 log 10 x d x > log 10 n > 1 993 log 10 x d x \int_1^{994} \log_{10} x \, dx > \sum \log_{10} n > \int_1^{993} \log_{10} x \, dx . This gives us 2548.15 > > 2545.15 2548.15 > \sum > 2545.15 . It could be improved slightly by accounting for the first few terms (which give the greatest error). In any case, this gets us close to the answer without much work.

Calvin Lin Staff - 7 years, 1 month ago

Log in to reply

It can also be done purely analytically without any use of computation by using Stirling's approximation (which gives both a lower and matching upper bound) log 10 ( n ! ) 1 2 log 10 ( 2 π n ) + n log 10 ( n / e ) \log_{10}(n!)\asymp \frac{1}{2}\log_{10}(2 \pi n) + n \log_{10} (n/e)

Abhishek Sinha - 5 years, 2 months ago

hi.shaun well I knew this formula but i still did not understand how you calculated the log of 993! please explain in detail

Max B - 7 years, 1 month ago

Log in to reply

it follows as the follwing: log 4! = log (4 3 3 2 1) = log 4 + log 3 + log 2 + log 1
{as, log (m*n)= log m + log n } there fore ... the problem follows the ceiling function.. to get the result of the problem

NEELESH SRIVASTAVA - 7 years, 1 month ago

It should actually be d = y + 1 d=\lfloor y\rfloor +1 . Instead of remembering the formula incorrectly, try to figure out how the formula works. The basic idea is that y = f ( x ) = log 10 x y=f(x)=\log_{10}x is strictly increasing on ( 0 , ) (0,\infty) and,

x Z + , y = f ( x ) = m Z 0 x = min ( A m + 1 ) \forall~x\in\Bbb{Z^+}~,~y=f(x)=m\in\Bbb{Z_{\geq 0}}\iff x=\min(A_{m+1})

where A i A_i denotes the set of all i i -digit positive integers i Z + \forall~i\in\Bbb{Z^+} .

Prasun Biswas - 5 years, 4 months ago
Scott Handelman
Apr 27, 2014

Is it cheating to use built-in modules? Python solution:

from math import factorial
print len(str(factorial(993)))

Cool! I didn't think of using len and I used log.....

展豪 張 - 5 years, 2 months ago
Daniel Gabrić
Apr 22, 2014

Easy stuff

public class factorialDigits {
    public static void main(String[] args) {
        BigInteger f = factorial(993);
        System.out.println(f.toString().length());
    }
    public static BigInteger factorial(int n) {
        BigInteger prod = BigInteger.ONE;
        for (int i = 2; i <= n; i++) {
            prod = prod.multiply(BigInteger.valueOf(i));
        }
        return prod;
     }
}
Jesse Nieminen
Mar 5, 2016

Using Java:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//Defined for non-negative integers
public static BigInteger factorial(int number) {
    BigInteger factorial = BigInteger.ONE; //Equals 1

    //Loop through all integers from 2 to number (we can skip 1 since multiplying by 1 does nothing)
    for (int i = 2; i <= number; i++) {

        BigInteger current = new BigInteger(String.valueOf(i)); //Equals i

        factorial = factorial.multiply(current); //Multiply factorial by the current number

    }

    return factorial; //Return factorial
}

public static int length(BigInteger number) {

    return number.toString().length(); //Get the number as a string and get its length

}

public static void main(String[] args) {

    System.out.println(length(factorial(993))); //Compute the factorial and print it

}

Which prints out 2547 \boxed{2547}

Anubhav Balodhi
Jun 2, 2015

I wrote a code in Python: (http://ideone.com/VebyRT)

1
2
3
from math import factorial
x=factorial(993)
print(len(str(x)))

Kanav Gupta
Apr 28, 2014

To calculate the value , I just simply used this code in Python-

def f(n):
  if n==0:
    return 1
  return n*f(n-1)

x=str(f(993))

print len(x)

This gave me solution 2547

I did exactly the same ^_^ :D

Krishna Ar - 6 years, 7 months ago
Masbahul Islam
Apr 26, 2014

Python code:

def masba(n):

if n==1:

  return 1

else:

  return n*masba(n-1)

print len(str(masba(993)))

Aditya Mishra
Apr 25, 2014

def fact(i):

if(i==1):

    return 1

else:

    return i*fact(i-1)

x=fact(993)

i=0

while(x>0):

x//=10

i+=1

print(i)

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...