Let the number whose factorial we need to find be 13. 13! equals 6227020800 which can be written as 6.210^9. You are storing it in an int variable âfâ whose maximum value can be equal be to 2,147,483,647 ~ 210^9. Thus you might be getting a wrong answer because of integer overflow condition.
Even after using long long there will be an overflow condition for factorial of 23. Here you need to store the answer in a different way like using an array to store the digits of the answer rather than just storing it in a primitive datatype.
#include<bits/stdc++.h> // includes every standard library file
#include<boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using namespace std; #define ll long long #include