void call_sqrt(char *number,char *result,char *extra){ int num,start,e,mul,l,r=0,len; char left[MAX],after[MAX]; char who[5],temp[MAX],two[5]; len=strlen(number); if(len%2==0){ num=10*(number[0]-'0') + number[1]-'0'; start=2; } else{ num=number[0]-'0'; start=1; } mul=(int) sqrt(num); result[0]=mul+'0'; result[1]='\0'; if(num-mul*mul ==0) extra[0]='\0'; else sprintf(extra,"%d",num-mul*mul); for(;start<len;start+=2){ e=strlen(extra); extra[e]=number[start]; extra[e+1]=number[start+1]; extra[e+2]='\0'; two[0]='2'; two[1]='\0'; call_mult(result,two,left); l=strlen(left); for(mul=9;mul>=0;mul--){ who[0]=mul+'0'; who[1]='\0'; strcat(left,who); call_mult(left,who,after); if(call_minus(extra,after,temp)==1){ result[++r]=mul+'0'; result[r+1]='\0'; strcpy(extra,temp); break; } else left[l]='\0'; } } result[++r]='\0'; }
int main() { char fir[MAX],sec[MAX],res[MAX]; while(scanf("%s%s",&fir,&sec)==2) { call_mult(fir,sec,res); int len=strlen(res); for(int i=0;i<len;i++) printf("%c",res[i]); printf("\n"); } return 0; }
int main(){ char fir[MAX],sec[MAX],res[MAX]; int i,p; while(scanf("%s %d",&fir,&p)==2){ if(fir[0]=='0'&&p==0) break; memset(res,0,MAX); strcpy(res,"1"); for(i=0;i<p;i++) call_mult(fir,res,res); int len=strlen(res); for(int i=0;i<len;i++) printf("%c",res[i]); printf("\n"); } return 0; }
int main() { int i,j,k; char finalResult[MAX],Result[MAX],intToString[100],intToStringFinal[100]; for(i=0;i<=1000;i++) { nptr = new(factorial); if(i==0) { nptr->num=i; strcpy(nptr->fValue,"1"); nptr->next=NULL; head=NULL; head=tptr=nptr; } else if (i==1) { nptr->num = i; strcpy(nptr->fValue,"1"); nptr->next=NULL; tptr->next=nptr; tptr = nptr; } else if(i==2) { nptr->num = i; strcpy(nptr->fValue,"2"); nptr->next=NULL; tptr->next=nptr; tptr = nptr; } else if (i==3) { nptr->num = i; strcpy(nptr->fValue,"6"); nptr->next =NULL; tptr->next=nptr; tptr = nptr; } else if (i==4) { nptr->num = i; nptr->next = NULL; strcpy(nptr->fValue,"42"); tptr->next = nptr; tptr = nptr; } else { if(i==5) strcpy(finalResult,"42"); sprintf(intToString,"%d",i); reversestr(intToString,intToStringFinal); call_mult(finalResult,intToStringFinal,Result); strcpy(nptr->fValue,Result); nptr->num=i; nptr->next=NULL; tptr->next=nptr; tptr=nptr; strcpy(finalResult,Result); } } double N,M; while (scanf("%lf %lf",&N,&M)!=EOF) { if(N==0 && M==0) break; char ResultForN[MAX],ResultForM[MAX],ResultForNminusM[MAX]; ResultForM[0]=ResultForN[0]=ResultForNminusM[0]='\0'; for(tptr=head,i=0;tptr->num<=N+1;tptr=tptr->next,++i) { if(tptr->num == N) strcpy(ResultForN,tptr->fValue); if(tptr->num == M) strcpy(ResultForM,tptr->fValue); if(tptr->num == N-M) strcpy(ResultForNminusM,tptr->fValue); } strcpy(Result,ResultForN); reversestr(Result,ResultForN); double factOfN = atof(ResultForN); strcpy(Result,ResultForM); reversestr(Result,ResultForM); double factOfM = atof(ResultForM); strcpy(Result,ResultForNminusM); reversestr(Result,ResultForNminusM); double factOfN_M = atof(ResultForNminusM); long double lower = factOfN_M*factOfM; long double C = (long double) factOfN /( (long double) lower); printf("%.0lf things taken %.0lf at a time is %.0llf exactly.\n",N,M,C); } return 0; }
int main() { int i,j,k; char finalResult[MAX],Result[MAX],intToString[100],intToStringFinal[100]; for(i=0;i<=1000;i++) { nptr = new(factorial); if(i==0) { nptr->num=i; strcpy(nptr->fValue,"1"); nptr->next=NULL; head=NULL; head=tptr=nptr; } else if (i==1) { nptr->num = i; strcpy(nptr->fValue,"1"); nptr->next=NULL; tptr->next=nptr; tptr = nptr; } else if(i==2) { nptr->num = i; strcpy(nptr->fValue,"2"); nptr->next=NULL; tptr->next=nptr; tptr = nptr; } else if (i==3) { nptr->num = i; strcpy(nptr->fValue,"6"); nptr->next =NULL; tptr->next=nptr; tptr = nptr; } else if (i==4) { nptr->num = i; nptr->next = NULL; strcpy(nptr->fValue,"42"); tptr->next = nptr; tptr = nptr; } else { if(i==5) strcpy(finalResult,"42"); sprintf(intToString,"%d",i); reversestr(intToString,intToStringFinal); call_mult(finalResult,intToStringFinal,Result); strcpy(nptr->fValue,Result); nptr->num=i; nptr->next=NULL; tptr->next=nptr; tptr=nptr; strcpy(finalResult,Result); } } while (scanf("%d",&i)!=EOF) { printf("%d!\n",i); for(tptr=head;tptr->num!=i;tptr=tptr->next) ; reversestr(tptr->fValue,Result); for(i=0;Result[i]=='0';i++) ; printf("%s\n",Result); } return 0; }