SPOJ24(Small factorials)

24. Small factorials

Problem code: FCTRL2

You are asked to calculate factorials of some small positive integers.

Input

An integer t, 1<=t<=100, denoting the number of testcases, followed by t lines, each containing a single integer n, 1<=n<=100.

Output

For each integer n given at input, display a line with the value of n!

Example

Sample input:
4
1
2
5
3

Sample output:

1
2
120
6

 

 

//2009-05-17 13:16:10     Xredman    Small factorials    accepted     0.43      219M      JAVA 
import java.io.*;
import java.util.*;
import java.math.*;

public class Main {

    
public static void main(String[] args) {
        
int n, T;
        
int i;
        BigInteger ans 
= null, ti = null;
        Scanner cin 
= new Scanner(System.in);
        T 
= cin.nextInt();
        
        
for(int k = 0; k < T; k++)
        
{
            n 
= cin.nextInt();
            
            ans 
= ans.valueOf(1);
            
            
for(i = 2; i <= n; i++)
            
{
                ti 
= ti.valueOf(i);
                
//System.out.println("ti  " + ti);
                ans = ans.multiply(ti);
            }

            System.out.println(ans);
            
        }

   }


}


posted on 2009-05-17 19:22  Xredman  阅读(149)  评论(0编辑  收藏  举报

导航