Aha! That's how you use this function. I have read in the manual but did not understand it right away how and for what to use it. Thank you.
I did some testing, that's exactly what I needed :)
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <gmp.h>
int main()
{
mpz_t n;
mpz_t a;
mpz_t b;
mpz_t c;
mpz_t base;
int x;
int i;
mpz_init(n);
mpz_init(a);
mpz_init(b);
mpz_init(c);
mpz_init_set_ui(base,2);
time_t sec;
sec=time(NULL);
for (x = 1;x <1000000;x++)
{
//2^a+2^b-1
//2^5000+2^1000-1
mpz_setbit(n,5000);
for(i=0;i<=999;i++)
{
mpz_setbit(n,i);
}
}
printf("time=%ld sec.\n",time(NULL)-sec);
sec=time(NULL);
for (x = 0;x <1000000;x++)
{
//2^a+2^b-1
//2^5000+2^1000-1
mpz_pow_ui(a,base,5000);
mpz_pow_ui(b,base,1000);
mpz_add(c,a,b);
mpz_sub_ui(c,c,1);
}
printf("time=%ld sec.\n",time(NULL)-sec);
mpz_clear(n);
mpz_clear(a);
mpz_clear(b);
mpz_clear(c);
return 0;
}
I guess the idea was not half bad, but its the slower solution. The loop method takes 3 sec. on my machine and the GMP implementation 0 sec.
At least my idea works
hunson