1 #include<stdio.h> 2 #include<string.h> 3 #include<algorithm> 4 #include<math.h> 5 using namespace std; 6 int main() 7 { 8 int n; 9 while(scanf("%d",&n),n) 10 { 11 int p=n,sum=0,temp; 12 while(p>=3) 13 { 14 temp=p/3; 15 p%=3; 16 sum+=temp; 17 p+=temp; 18 } 19 if(p==2) 20 sum++; 21 printf("%d ",sum); 22 } 23 return 0; 24 }