Factorial Calculator

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 1.0s
Python 2 2.0s
Python 3 2.0s
Memory limit: 256M

Author:
Problem type

It's the final year of high school for the CS nerd, so he should find a girl soon. In particular, he has an interest in one particular girl (and for privacy reasons, we will refer to her as "the girl"). The CS nerd isn't feeling very confident about approaching the girl, so he asks Jason to help boost his confidence.

Of course, the perfect method of boosting confidence is by solving a problem! Jason asks the CS nerd to calculate N!, where N! = N \times (N-1) \times \dots \times 2 \times 1. The CS nerd thinks that the task is simple (since he can simply use his super awesome calculator), but Jason reminds him that his calculator cannot calculate factorials above 69!. If the CS nerd solves this problem, his confidence will be boosted higher than normal since he solved a math problem.

Since factorials can become very, very large, Jason does not want the CS nerd to list every single digit in his answer, so Jason wants the CS nerd to write his answer in computerized scientific notation, which is in the form <coefficient>e+<exponent> where the coefficient is a real number between 1 (inclusive) and 10 (exclusive), and the exponent is an integer. This notation represents the number:

\displaystyle \text{coefficient} \times 10^\text{exponent}

Can you help the CS nerd solve this problem in order to gain confidence?

Constraints

2 \le N \le 10^6

Let c be the coefficient of N! in computerized scientific notation. It is guaranteed that 1+10^{-6} < c < 10-10^{-6}.

Subtask 1 [30%]

N \le 150

Subtask 2 [20%]

N \le 2000

Subtask 3 [50%]

No additional constraints.

Input Specification

The first and only line of input will contain a single integer, N.

Output Specification

Print the value of N! in computerized scientific notation.

Your answer will be considered correct if the coefficient is within an absolute error of 10^{-6} and the exponent matches.

Sample Input 1

4

Sample Output 1

2.4e+1

Explanation for Sample Output 1

Note that 4! = 4 \times 3 \times 2 \times 1 = 24 = 2.4 \times 10^1. Therefore, the coefficient is 2.4 and the exponent is 1.

Sample Input 2

70

Sample Output 2

1.197857167e+100

Comments

There are no comments at the moment.