I recently encountered a problem in the beginner question FCTRL2.
This is my code:
This produced the desired output when I ran it in Dev C++. However, when I submit my question, they keep telling it is a wrong answer.
I would like to know whether my approach to the problem is wrong or not.
Well it should give wrong answer indeed. You are using int data type which has a range of approximately 10^9 but the constraints of the problem are upto 100 .
So obviously this integer won’t fit in int data type and for that matter it won’t even fit in long long int or unsigned long long int .
So you need to change your approach and once you are done with coding check the value of 100! once to get an idea whether your code is correct or not.
Thanks for your feedback. I understood my problem. If it were Java or Python I could use the Big Integer class. I am not sure whether they work on C/C++. I guess the safest way were to treat my numbers as strings and carry on with my code, if I am correct.