# BigInteger in C++

Lately, I’m trying to code few basic problems in C++ and finding it hard in some cases when problems with BigInteger arises.

With Java, I can easily do,
BigInteger b = new BigInteger(“111111111111111111111111111111111111111”);

That above value could not be even held in a long datatype in java.

Similarly If I want to do the same in C++, Is there any straightforward piece of code [expecting in 2 to 3 lines], such that the usage becomes easy.

P.S : Couldn’t find anything useful in google / codeforces - one such blog had hectic big explanation and didn’t understand a thing

you can try the following library in c++
instructions to use it are also present in readme file.

1 Like

Thanks!

But the code is too large and still didn’t understand. Need to spend a day or two to sit and understand how BigInteger works properly before using it blindly.

1 Like

Use Boost Multiprecision Library.

It’s as simple as including a header file

Include these lines in your code!

``````#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
``````

Now simply use your BigInt like this

``````cpp_int a;
``````
7 Likes

Thanks a lot

You can use this , little more documented (still incomplete, but does most jobs).
P.S. I don’t own the codes. All I own is documentation.

1 Like

@s5960r what is the range of this “cpp_int” ?

thanks , this is working fine
tested for this problem — solution

@ubc_123
It stores numbers like an array internally maybe…so it’s pretty big🤣 probably like 10^6 or 10^7

Be careful tho… All arithmetic operations would take O(n) where n is number of digits

yes O(n*n) for multiplication
we cannot avoid that unless if we can implement Karatsuba

1 Like

I think it is much more. You can calculate 20! that is upto 18+ length

@koulick_424
No i mean… 10^7 digits

1 Like

Python is the solution

2 Likes

LOL, seeing c++ and python solution’s makes me think those languages are Rocket science’s :P.

For example, see this code : https://www.codechef.com/viewsolution/26980017

Woof!!!