user1611281
user1611281

Reputation: 3

How to handle big data element in c++?

I want to divide the return value of pow(2.0,(n-8)) by 86399. The problem is 10 <= n <= 100000000.

How can I handle such a large return value?

I'm on Ubuntu 11.10 64 bits, using C++ 4.0.0-8

Upvotes: 0

Views: 282

Answers (3)

Eric
Eric

Reputation: 3172

This discussion should answer your question Modular Exponentiation for high numbers in C++

For numbers that large, you'll have to do something clever. There's no way you can represent that full number naively in any reasonable way without bigint libraries, and even then it's really too big for brute force. The number itself would take up tens of megabytes.

Upvotes: 0

ssb
ssb

Reputation: 7502

One very easy way would be to use GMP -- http://gmplib.org/

Upvotes: 1

bchurchill
bchurchill

Reputation: 1420

You can't unless you use a big numbers library. 64 bits can't hold a number that big. And even then, it will probably take a while. 2^(86392) has about 26000 digits in it.

If you want to get just a modulus, there are some nice algorithms for that. See http://en.wikipedia.org/wiki/Modular_exponentiation.

If you want to try bignums still, check out http://gmplib.org/.

Upvotes: 4

Related Questions