就是简单取余取模:
#include <iostream>
using namespace std;
void helper(int val){
int res = 0;
while (val >= 3){
res += val/3;
val = val - 2 * (val/3);
}
if (val == 2) ++res;
cout << res << endl;
}
int main(){
int val;
while (cin >> val){
if (val) helper(val);
else break;
}
return 0;
}