int main(){ int n; while(scanf("%d",&n)){ if(n==0) break; if(isPowerofTwo(n)) printf("%d\n",n); else printf("%d\n",(n-nearestPowerofTwo(n))*2); } return 0; }
vector<int> countBits(int num) { vector<int> res; res.push_back(0); if(num == 0) return res; int t = -1; for(int i = 1; i <= num; i++) { if(isPowerofTwo(i)) { res.push_back(1); t = i; } else { res.push_back(res[t] + res[i-t]); } } return res; }