水题。
int n; int main() { cin>>n; int res=n; int carry=0; while(n) { n+=carry; carry=n%3; n/=3; res+=n; } cout<<res<<endl; //system("pause"); return 0; }