That is the question. I am not looking for a fast implementation but basically, it should at least be able to do this : + Calculate 2^200000 in a minute or less
+ Calculate 20000! in a minute or less
I do not want a C++11 implementation, my complier does not support it. I would be helpful if someone can help me find a proper one. Thanks.
P.S : I am a kid, I know it is a crazy idea, but I really want to know if there is an integer variable that can store a number that is even bigger than what a uint64_t can store. Thank you very much.
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
int main()
{
boost::multiprecision::cpp_int pow = 1 ;
for( int i = 0 ; i < 20000 ; ++i ) pow *= 2 ;
std::cout << "2^20000 has " << pow.str().size() << " digits\n" ;
boost::multiprecision::cpp_int fact = 1 ;
for( int i = 2 ; i < 20001 ; ++i ) fact *= i ;
std::cout << "20000! has " << fact.str().size() << " digits\n" ;
}
------ clang++ ------
2^20000 has 6021 digits
20000! has 77338 digits
real 0m0.465s
user 0m0.460s
sys 0m0.000s
--------- g++ --------
2^20000 has 6021 digits
20000! has 77338 digits
real 0m0.540s
user 0m0.528s
sys 0m0.008s
#include <iostream>
#include <boost/multiprecision/gmp.hpp>
int main()
{
boost::multiprecision::mpz_int pow = 1 ;
for( int i = 0 ; i < 20000 ; ++i ) pow *= 2 ;
std::cout << "2^20000 has " << pow.str().size() << " digits\n" ;
boost::multiprecision::mpz_int fact = 1 ;
for( int i = 2 ; i < 20001 ; ++i ) fact *= i ;
std::cout << "20000! has " << fact.str().size() << " digits\n" ;
}
------ clang++ ------
2^20000 has 6021 digits
20000! has 77338 digits
real 0m0.106s
user 0m0.076s
sys 0m0.000s
--------- g++ --------
2^20000 has 6021 digits
20000! has 77338 digits
real 0m0.098s
user 0m0.088s
sys 0m0.008s