I am trying to raise and arbitrarily larger number to an arbitrarily large power. As far as I can see, GMP has a function that does this, but applies modulo to the result, and a function that lets me raise an arbitrary number to an unsigned int exponent. Is there a way around this?
I am trying to raise and arbitrarily larger number to an arbitrarily large power.
Share
It’s an
unsigned long intexponent, so if you are on a system whereunsigned longis 64 bits (or more), that will take you beyond the available memory for the next few years (2^(2^64-1)needs a couple of Exabytes storage).If you’re on a system with 32-bit
unsigned long, you can split the exponent in two parts,and that has very good chances of needing more memory than you have.
A further problem is that GMP uses
ints to count the limbs, so typically you can’t have numbers using more than(2^31 - 1)*BITS_PER_LIMBbits anyway (BITS_PER_LIMBis 32 or 64 depending on the platform, usually).If you think you need
a^bwherea > 1andbdoesn’t fit in anunsigned long (long), you will have problems with GMP and your memory anyway.