ans每次累加商
n每次更新为商和余之和
最后到了3以下时,判断是否为2(即不为1和1),为2则再加一即可
#include<iostream>
using namespace std;
int main () {
int n;
while (cin >> n) {
int ans = 0;
if (n == 0) {
break;
}
while (n >= 3) {
ans += n / 3;
n = n / 3 + n % 3;
}
if (n == 2) {
ans++;
}
cout << ans << endl;
}
return 0;
}

京公网安备 11010502036488号