Hi ,I am trying to do this factorial problem ,I tried custom inputs till 100 ! and got correct answers ,I even checked my answers to those crct submitted solutions found on net and both the outputs are same for 1 to 100! ,but still my solution is getting wrong answer ,Here is my submitted solution .

Consider the test input:

```
3
5
10
15
```

1 Like

Try This

```
/* package codechef; // don't place package name! */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
/* Name of the class has to be "Main" only if the class is public. */
class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader scin = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(scin.readLine());
while (t>0){
int n;
BigInteger bigInteger = new BigInteger("1");
n = Integer.parseInt(scin.readLine());
for (long i=2; i<=n; i++){
bigInteger = bigInteger.multiply(BigInteger.valueOf(i));
}
System.out.println(bigInteger);
t--;
}
}
}
```

1 Like

Thanks for the help this test case is failing but when i ran the code for t=100 and n from 1 to 100 everthing is working fine.

I know; that’s why I gave you it

thnx its working.

# this code got submitted successfully ,thnx for helping me in identifing the wrong test case

```
t=int(input())
f=[]
f.append(1)
f.append(1)
j=2
while(t>0):
n=int(input())
try:
if f[n]:
pass
except IndexError:
for i in range(j,n+1):
f.append(f[i-1]*i)
j=n+1 #I have changed j from j+=1 to j=n+1
print(f[n])
t-=1
```

1 Like