Big Integers

I have a problem to solve on Hackerrank. I am still confuse about the very long factorial can someone help me. How we can store that big number ?

25th Jul 2017, 4:04 PM
thong nguyen
thong nguyen - avatar
3 Answers
+ 4
Any program that needs to save really huge integers that can be 50+ digits long. The absolute maximum primitive data type in C++ is unsigned long long int with a maximum value 18446744073709551615 which is only 20 digits long. Here's the link to the limits of C++: http://www.cplusplus.com/reference/climits/
25th Jul 2017, 4:12 PM
Apoorva Shenoy Nayak
Apoorva Shenoy Nayak - avatar
+ 2
C++ supports up to 2^64 - 1. There is also the __uint128_t type which goes up to 2^128 - 1, but is unsupported by the library, so you can't print the number without overloading the << operator yourself. Even this probably isn't enough to store really big factorials. So for C++ you're gonna have to implement your own. The easiest way is probably to take a string and use your math skills to do multiplication like you did in high school.
25th Jul 2017, 4:32 PM
Dennis - avatar