FCTRL2 executes in my system but codechef doesnt accept

import java.util.Scanner;

class Demo

{

public static int A(int no)
{
int count=1;
for(int m=1;m<=no;m++)
{
count = count*m;
}

return count;
}

public static void main(String args[])
{
Scanner s = new Scanner(System.in);
int n=s.nextInt();
for(int i=0;i<n;i++)
{
	int num = s.nextInt();
	System.out.println(A(num));

}




     }

}

Have a look at this link. You are using “int” type to store n! where n is between 1 to 100. n! of numbers larger than 16 cannot be stored in int type or long long type. Ypu need to use “big integer” type to store factorial of larger numbers.

2 Likes