#include #include #include void ins(mpz_t *des,int *n,mpz_t obj); void mpz_pow(mpz_t base,mpz_t bs,mpz_t ex); int main() { int n; mpz_t bs,ex,res,v[9360]; mpz_init(res); mpz_init(bs); mpz_init(ex); mpz_init(*v); n=0; for(mpz_set_si(bs,2);mpz_cmp_si(bs,101)<0;mpz_add_ui(bs,bs,1)) for(mpz_set_si(ex,2);mpz_cmp_si(ex,101)<0;mpz_add_ui(ex,ex,1)) { mpz_pow(res,bs,ex); // There is also a standard function ins(v,&n,res); // but it requires one more variable. } printf("\n\t%i\n\n",n); system("pause"); return 0; } void ins(mpz_t *des,int *n,mpz_t obj) // This function puts the result { // in the 'v' array checking the if(*n==0) // value hasn't been already added. { mpz_set(des[0],obj); *n=1; } else { int i=0; for(;i<=*n;i++) if(mpz_cmp(des[i],obj)>0||i==*n) { if(mpz_cmp(des[i-1],obj)!=0) { *n=*n+1; int j=*n; for(;j>i;j--) mpz_set(des[j],des[j-1]); mpz_set(des[i],obj); } i=*n+1; } } } void mpz_pow(mpz_t res,mpz_t bs,mpz_t ex) // Working with mpz all variables are { // passed with pointers (also if not mpz_t exp; // expressed!). mpz_init(exp); mpz_set(exp,ex); mpz_set_si(res,1); for(;mpz_cmp_si(exp,0)>0;mpz_sub_ui(exp,exp,1)) mpz_mul(res,res,bs); }