int main(){ int n,*a=NULL,*b=NULL,a1,b1,i,r,x=1,y=1; scanf("%d",&n); while(n!=0){ a=&x;b=&y; r=1;a1=1;b1=1; for(i=1;i<n;i++){ if((a1+1)%b1==0 && (a1+1)/b1==2) { b1++; } a1++; *b=b1;*a=a1; if((*a)%(*b)==0){ *b=1; *a=(*a)/(*b); }else{ yuefen(a1,b1,a,b); } r+=*b; } printf("%d\n",r); scanf("%d",&n); } return 0; }
void yuefen(int a1,int b1,int *a,int *b){ if(b1==0 && a1!=1){ *a=*a/a1; *b=*b/a1; return; }else if(b1==0 && a1==1){ return; } yuefen(b1,a1%b1,a,b); }
void m_div(int a, int b, int c, int d) { int fz = a * d; int fm = b * c; yuefen(fz, fm); }
void m_sub(int a, int b, int c, int d) { int fz = a * d - b * c; int fm = b * d; yuefen(fz, fm); }
void m_mul(int a, int b, int c, int d) { int fz = a * c; int fm = b * d; yuefen(fz, fm); }
void m_add(int a, int b, int c, int d) { int fz = a * d + b *c; int fm = b * d; yuefen(fz, fm); }