Really big number
First of all apologies if there is already a topic like this but I have not found... I need to know how to handle a really big number such as the result of 789^2346:
#include <io开发者_如何学Cstream>
#include <cmath>
using namespace std;
int main () {
cout << pow(789,2346) << endl;
}
You could try the GNU MP Bignum Library or ttmath. This link point to some samples. It is very easy to use.
You need a "big number" library. A popular choice is GNU's Multiple Precision Arithmetic Library, which has a C interface. I's also been around for a while. Another one, for C++, is Big Integer Library.
I'm sure there is a list of bignum libraries on SO somewhere, but I cannot find it. There is a tag you could stroll through.
You can consider NTL (Number Theory Library) for C++ - http://www.shoup.net/ntl/ . It's very easy to use.
If you can relax C++ requirement, Perl and Python support big integers natively. PHP supports via bcmath or gmp extensions.
精彩评论