Public Group

# How to use BigInteger in c++?

This topic is 3081 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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 on other sites
You don't need a bigint. Read the instructions carefully again.

##### Share on other sites
eh i did, is there supposed to be wordplay? My english isn't very good.. :S

##### Share on other sites
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 on other sites
Quote:
 Original post by WaaayoffMeh... 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 on other sites
what do you mean? with 5 the max is 9*9*9*9*9. How can you guarantee that the 1000 digit number has 5 consecutive 9s?

##### Share on other sites
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.

ah Thanks :)

##### Share on other sites
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.

1. 1
Rutin
26
2. 2
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 21
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631763
• Total Posts
3002189
×