1

How can i handle very large integers like 2^100000000 in c++?

I found no solution for this on internet that gives an exact answer.

Is there any mechanism that gives correct value in c++ for such large integers?

hanugm
  • 1,127
  • 3
  • 13
  • 44
  • 4
    Have you searched on stackoverflow? There must be at least one answer suggesting e.g. gmp. There's no _standard_ way (yet), but there are a ton of ways. Look closer. – stefan Nov 02 '13 at 20:52
  • 1
    Try searching for [BigNum](http://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic). – crashmstr Nov 02 '13 at 20:53
  • 1
    It's a bit out of the standard range to call it "integer" -- your number has 3 *million* digits. Maybe that's why your search turned up nothing. – Jongware Nov 02 '13 at 20:56
  • i searched on stackoverflow and about bignum ... but very long process than my program :( – hanugm Nov 02 '13 at 20:56
  • What do you mean by 'handle'? Do you just want to get the decimal representation of such a number or do you want to do calculations with it? – mattnewport Nov 02 '13 at 21:01

3 Answers3

4

What you are looking for is called arbitrary precision arithmetic, you will find numerous libraries and educational resources with some googling.

Raff.Edward
  • 6,404
  • 24
  • 34
0

You can represent given number as a string and convert it to array with integer digits. But the simplest way to google by keywords "long arithmetic c++ library" or something.

indiv
  • 17,306
  • 6
  • 61
  • 82
mikhdm
  • 109
  • 2
  • 12
0

Maybe you want to use a Computer Algebra System (CAS), which would represent your expression like this:

class Pow : public Expr {
  Number base;
  Number exp;
};

Pow expr = new Pow(2, 100*1000*1000);

A CAS then allows you to manipulate these expressions structurally instead of the concrete values.

Roland Illig
  • 40,703
  • 10
  • 88
  • 121