How to use BigInteger in c++?

Started by
7 comments, last by alvaro 14 years, 2 months ago
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!!
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
Advertisement
You don't need a bigint. Read the instructions carefully again.
eh i did, is there supposed to be wordplay? My english isn't very good.. :S
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
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!!
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
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.
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?
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
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 :)
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
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.

This topic is closed to new replies.

Advertisement