Please find out why i am getting wrong answer (FCTRL2)

Try n=100 as input in your you will get this!!!
Basically, 100! is a large value and can’t be stored in int data type, In fact 17! will come out to be negative if you try.

1 Like

This is because long long cannot handle answer as large as 100!. It has digits more than 157 which is clearly out of range of long long. Now you can do this in two ways-

  1. The most obvious way is to use strings.
  2. A library named boost multiprecision is present in C++, which has a very high range and can handle these value. To know more, check this link-
1 Like