Way to use big integer in C++

Hello all,

I would like to share a library which provides integer, rational and floating-point types in C++ that have more range and precision than C++'s ordinary built-in types. You can easily use this library to get values equal to even 100 ! (100 factorial) and larger. This library also extends expression template support to standard library functions like abs or sin with number arguments

I will give code example below so that you can use it instead of array multiplication or division and get fast AC in easy problems which require arithmetic operations on large numbers.

If you want to read more about it, you can see here.

Code to compute 100! and 99! : link

Here are some problems where you can try this library :



This library works fine on CodeChef and HackerEarth. However, it doesn’t works on HackerRank and CodeForces.

Thank You !!


Hello , you guys can even refer to this Bigint Class which will work everywhere you just need to include it in your solution and it is really simple to use . It provides nearly every operations and they are optimised to quite an extent (it uses karatsuba for multiplication and optimised memory). Btw when using this in a contest just add a comment in your code explaining the link the class to make sure that no issues raises .

cheers !


@torque I have solved the question MULTISRM by using this library.it is running correctly on ideone link but it gives compilation error on codechef and also on codeblocks.some of the errors are:-
prog.cpp:1:44: error: boost/multiprecision/cpp_int.hpp: No such file or directory
prog.cpp:3: error: ‘boost’ has not been declared
prog.cpp:3: error: ‘multiprecision’ is not a namespace-name
prog.cpp:3: error: expected namespace-name before ‘;’ token

@torque , Can I use this to directly solve the Lucky Number 72 (LUCK72) problem that appeared on NIT Kurukshetra code battle 2 yesterday? If not, then what is the possible range of the integers that this library can be used to operate upon?

1 Like

Providing a link to post on codeforces explaining how to use big integers in c++.


Happy Coding…

@torque this program is working on codechef ide while showing error in hackerrank.
solution.cc:1:9: fatal error: boost/multiprecision/cpp_int.hpp: No such file or directory.
namespace mp = boost::multiprecision;
using namespace std;

int main()
int n;
mp::cpp_int fac=1;
for(int i=1;i<=n;i++)
return 0;
`can you please tell me?

You must be using C++ 4.3.2. Use C++ 14. It should not give compilation error in C++14

Yes, you can use it in such questions but it would give TLE on LUCKY72 as operations are costly in this header file and there are MOD operations involved in LUCKY72 which are even more costly.

he,@torque mentioned that this doesn’t work in hackerrank and codeforces !

Greaaaaaat!!! Nice :slight_smile:

Can I include reference in comments and use it in the long challenge ?

C++ uses big integers but when you use specific function. To know more about these functions visit https//www.sehzadi.com

I am getting this error while using this library.

Help :slightly_smiling_face:

1 Like

You’re including boost::lexical_cast and using boost::to_string. Include the proper header file for boost::to_string, which is “boost/exception/to_string.hpp”.

1 Like

No, It also doesn’t work in C++14. I have done another problem in which I have used this library.But it is not working on codeforces though it runs in idegeeksforgeeks

No, It also doesn’t work in C++14. I have done another problem in which I have used this library.But it is not working on codeforces though it runs in idegeeksforgeeks

Isn’t there any pow() function in this library? How will you deal with it in bigint ?