2

I'm solving some problems on UVA online judge now, and I'm running into scenarios where I have to store very large integer values (15 digits or more sometimes). Is there any way I can do it without the usage of third-party libraries? [Anything similar to BigInteger class in java?].

Zoneur
  • 1,101
  • 9
  • 20
Raj
  • 4,342
  • 9
  • 40
  • 45
  • I did. I was able to find a few posts in SO as well, but I could only find third party implementations of BigIteger, but I'm not sure if I could use it on the online judge. – Raj Oct 17 '12 at 15:36
  • [This answer](http://stackoverflow.com/a/12869883/968261) may be helpful. – Alexey Frunze Oct 18 '12 at 01:06

5 Answers5

2

For pow with integers, http://en.wikipedia.org/wiki/Exponentiation_by_squaring

I would suggest GMP

Please refer this link:- C++ handling very large integers

Community
  • 1
  • 1
Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
1

Third party libraries are needed (unless you feel like writing your own library). GMP or MPIR are the ones to go for.

john
  • 7,897
  • 29
  • 27
1

No, there isn't such structure in standard library. But always you can check out GMP, MPFR or similar. Just search in Google.

Hauleth
  • 22,873
  • 4
  • 61
  • 112
1

You can use GNU's libgmp for arbitrary precision arithmetic in C.

Yefim Dinitz
  • 414
  • 3
  • 9
0

The easiest to use would be Boost Multiprecision

http://www.boost.org/doc/libs/1_55_0/libs/multiprecision/doc/html/index.html

Here is a simple example

#include <boost/multiprecision/cpp_int.hpp>

using namespace boost::multiprecision;

int main(){

     cpp_int          a_really_big_number("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000");
     a_really_big_number += 7;

}
John Bandela
  • 2,416
  • 12
  • 19