We have given a large number now we can easily find out the factorial of this large number using boost multiprecision Library. Boost library has included a new multiprecision library in the current 1.53.0 release for C++ programmers who need more precision than 64 bits. Examples:
Input : 100 Output : 933262154439441526816992388562667004- 907159682643816214685929638952175999- 932299156089414639761565182862536979- 208272237582511852109168640000000000- 00000000000000 Input :50 Output : 3041409320171337804361260816606476884- 4377641568960512000000000000
C++
// CPP program to find factorial of large // number using boost library. #include <bits/stdc++.h> #include <boost/multiprecision/cpp_int.hpp> using boost::multiprecision::cpp_int;
using namespace std;
cpp_int Factorial( int number)
{ cpp_int num = 1;
for ( int i = 1; i <= number; i++)
num = num * i;
return num;
} int main()
{ int number = 100;
cpp_int fact = Factorial(number);
cout << fact << endl;
return 0;
} |
Output:-
933262154439441526816992388562667004- 907159682643816214685929638952175999- 932299156089414639761565182862536979- 208272237582511852109168640000000000- 00000000000000
Time Complexity: O(N) , where n is the value of the input number
Space Complexity: O(1)