質問

GNU GMP provides a functions called mpz_powm(rop, base, exp, mod) which allows me to power a very big integer value by another very big integer value. The function also forces me to modulate the result by the 4th parameter. That's what the "m" stands for in mpz_powm. The reason why there isn't a function without a mod parameter could be to avoid very big results which may fill up your whole memory like: 2^(2^64). I'd like to know if there is a possibility anyway to use that function without specifying a mod parameter by just taking the risk to reach your memory limit.

役に立ちましたか?

解決

You are looking for mpz_pow_ui (). If the argument you wish to pass does not fit in a single word then the result wouldn't fit in memory anyway (except for the trivial cases):

void mpz_pow_ui (mpz_t ROP, mpz_t BASE, unsigned long int EXP)

他のヒント

If you don't want to modulate your answer, you'll need to use mpz_pow_ui. However, because exponentiating with a large mpz_t will create an integer that won't fit into memory, the exponent has to be an unsigned long int.

So just convert your exponent, and then use the function:

mpz_pow_ui (rop, base, mpz_get_ui(exp))

However, if your exponent is larger than ULONG_MAX, (typically 2^32-1), you'll get overflow errors.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top