1

I'm trying to write an algorithm for a number theory/computer science merged class that can factor large numbers in better than exponential time. I am using the g++ compiler on a 64 bit machine but when I chain together long it will only allow me to do up to 2 longs. Is there any way to tell it to use an arbitrary amount of space for a variable?

  • I would check out this http://stackoverflow.com/questions/5344049/c-how-do-i-store-a-256-bit-number-and-how-do-i-convert-it-to-hex. The idea is the same. – linuxuser27 Mar 20 '11 at 17:21
  • 1
    possible duplicate of [C++ handling very large integers](http://stackoverflow.com/questions/124332/c-handling-very-large-integers) – taskinoor Mar 20 '11 at 17:23

2 Answers2

3

If you want just a collection of longs, you can declare an array of longs. But you don't want that. You want https://mattmccutchen.net/bigint/ BigIntegers :-)

Alternatives:

http://gmplib.org/

http://www.mpir.org/

(disclaimer: I haven't tested/used them)

Or if you want to implement them

How to implement big int in C++

I'll add that the C++ std library doesn't contain a big integer implementation (source STL big int class implementation )

Community
  • 1
  • 1
xanatos
  • 109,618
  • 12
  • 197
  • 280
1

You'll need a library. A good one is http://gmplib.org/

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720