Sign in to follow this  
Waaayoff

How to use BigInteger in c++?

Recommended Posts

Waaayoff    952
Problem #8 in project Euler requires me to work with a 1000 digit number. I could seperate it into smaller numbers and fit it into an array of unsigned __int64.. (Not the best way to do it i'm sure) and that's why i used google and came up with BigInteger. So my question is how to set it up (download? from where? where to put it?) and how to use it? (what to include, how to use the class...) Thanks!!

Share this post


Link to post
Share on other sites
Waaayoff    952
I just used my IE to highlight all the 9s and spent a minutes finding which number containing 3 9s (max of 9s) is higher.

Meh... The best solution is the easiest i guess. I'm curious though, i know how to write a code to do that, but i don't know how to fit 1000 digits into a variable!!

Share this post


Link to post
Share on other sites
Antheus    2409
Quote:
Original post by Waaayoff

Meh... The best solution is the easiest i guess. I'm curious though, i know how to write a code to do that, but i don't know how to fit 1000 digits into a variable!!


You don't need 1000 digits either. You need 5.

Share this post


Link to post
Share on other sites
CaspianB    309
Hint: You can store numbers as characters in a string and use atoi convert from characters to numbers.

And the most digits you need in an integer is five because the absolute largest value you can get with five single digit multiplications is 9^5 (as you pointed out) which equals 59049 - five digits.

Share this post


Link to post
Share on other sites
alvaro    21266
If you ever need a big-integer class (some problems in Project Euler do require one), take a look at GMP. They provide a nice C++ class called mpz_class that is really easy to work with.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this