Constraint is 1<=n<=100 , so you cannot store the factorials in variable of type int, use multiprecision int for c++ or use arrays to store the answer.
I believe, it must be due to the fact that long factorial values like 25! or 30! can’t be stored in “int data type” as it’s MAX_VALUE is pow(2, 31).
I suggest you to use “size_t (or) unsigned long long date type”, which has MAX_VALUE of pow(2, 64).
But anyway even it doesn’t allow you to use much more huge values like 100! or more.