Fast Factorial Calculator

View as PDF

Submit solution

Points: 7
Time limit: 0.6s
Memory limit: 64M

Author:
Problem type

quantum is not in a good mood today, so he has decided to torment people. He wants you to write a large factorial calculator. More specifically, he wants you to calculate very very very large factorials. He wishes you luck.

Input Specification

The first line of input will contain the integer N, 0 \le N \le 1\,000, the number of cases to follow.

The next N lines will contain an integer n, such that 0 \le n \le 2^{63}, whose factorial you are to calculate.

Output Specification

For every integer n, you are to output n! \bmod 2^{32}.

Sample Input

2
5
13

Sample Output

120
1932053504

Comments


  • 51
    d  commented on Feb. 14, 2016, 1:45 a.m. edited

    The value of n! \bmod 2^{32}-5 is more interesting to compute and optimize.


    • 60
      Riolku  commented on April 14, 2019, 7:04 p.m.

      No please all we wanted was happiness