#include #include #include #include int main() { int a,b,c,fl,vl2,vl3; char st1[11],st2[4]; mpz_t lim,sm,vl1; mpz_init(lim); mpz_init(sm); mpz_init(vl1); mpz_set_si(sm,0); mpz_set_si(vl1,123456788); mpz_set_si(lim,2147483647); // I have to set the 'lim' variable in this mpz_mul_ui(lim,lim,4); // way because gmp library doesn't allow it mpz_add_ui(lim,lim,1286608622); // in others. while(mpz_cmp(vl1,lim)<0) // The program cycles even 'vl1' variable { // doesn't achieve 9876543210, the maximun mpz_add_ui(vl1,vl1,1); // 0 to 9 pandigital number. mpz_get_str(st1,10,vl1); // for(a=0;st1[a]!='\0';a++); // This 'for' counts how long is the string. if(a<10) // { // st1[a+1]='\0'; // These lines are necessary to add an for(;a>0;a--) // initial zero-digit for values shorter st1[a]=st1[a-1]; // than 10 digits. st1[a]='0'; // } // if(pandg(st1)==0) // This function controls the string contains { // a pandigital number. for(a=c=vl3=fl=1;st1[a]!='\0';c=++a) // { // for(b=0;b<3;b++) // These lines divide the string into three st2[b]=st1[c++]; // sub-strings. First char is not considered. st2[b]='\0'; // vl2=atoi(st2); // This function converts a string to int. do{ // vl3++; // if(prime(vl3)==0) // Primes are calculated into this 'do-while'. b=0; // }while(b!=0); // if(vl2%vl3!=0) // All the sub-strings must be divisible { // for 2-3-5-7-11-13 consecutive primes. fl=0; // st1[a+1]='\0'; } if(c==10) a=9; } if(fl==1) mpz_add(sm,sm,vl1); } } gmp_printf("\n\t%Zd\n\n",sm); system("pause"); return 0; } int pandg(char *st) { int a,b,fl; fl=1; for(a=0;a<10&&fl==1;a++) for(b=fl=0;b<11;b++) if(a==st[b]-48) { b=11; fl=1; } return fl-1; } int prime(int val) { switch(val) { case 0: // case 1:return 1;break; // I have to specify these special numbers because the 'default' case would interpret them incorrectly! case 2:return 0;break; // default:{ if(val%2!=0) { int a=3; for(;a