Finding power for two large arguments

Alexander Smirnov axsmirnov at gmail.com
Thu Jan 16 11:20:10 UTC 2014


Hi,

First of all, thanks a lot for such a wonderful library like GMP! Now,
being just too impressed, I would like to perform expnentiation on two
relatively large numbers and in my application it goes like this:

#include <stdio.h>
#include <gmp.h>

int main(void) {

    mpz_t a;
    mpz_init_set_str(a,
"1234567890123456789012345678901234567890123456789012345678901234567890",
0);

    mpz_t b;
    mpz_init_set_str(b,
"9876543210987654321098765432109876543210987654321098765432109876543210",
0);

    gmp_printf("a = %Zd\n", a);
    gmp_printf("b = %Zd\n", b);

    mpz_t c;
    mpz_init_set_str(c, "0", 0);

    mpz_t mod;
    mpz_init_set_str(mod,
"10000000000000000000000000000000000000000000000000000000000000", 0);

    mpz_powm(c, a, b, mod);
    gmp_printf("a ^ b = %Zd\n", c);

    return 0;
}

However, I got 0 as a result and I think it because of modulo value.

Can I somehow got the result for c = a ^ b?

Best Regards,
Alexander


More information about the gmp-discuss mailing list