Thursday 1 January 2015

Small factorial (FCTRL2) spoj

small factorial use of Big integer in java

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
import java.util.Scanner;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes heres
int n,m,k,l,i;
BigInteger a,x,c;
a=new BigInteger("1");
Scanner w=new Scanner(System.in);
int t= w.nextInt();
while(t>0)
{
t--;
m=1;
a=new BigInteger("1");
n=w.nextInt();
for(i=1;i<=n;i++)
{ x=new BigInteger(Integer.toString(i));
a=a.multiply(x);


}
System.out.println(a);

}
/*BigInteger a=new BigInteger(Integer.toString(t));
System.out.println(a);*/
}
}

No comments:

Post a Comment