#include #include using namespace std; int tataku(int n) { long long temp1 = 1,temp2=n,temp3=0; while (temp2 > 0){ temp1 *= 2; //乗算 temp2 -= temp1; //食べた枚数を引く temp3++; //回数 } return temp3; } int main() { long long eat, number, temp = 0, number2 = 0; cin >> eat; number = tataku(eat); while (1){ if (number == 1) { number2 += number; break; } else if ((eat - (long long)pow(2.0, (double)number)) == 0) { number2 += number; break; } else if ((eat - (long long)pow(2.0, (double)number)) < 0) { number -= 1; number2 += number; if (number == 0)break; eat -= (int)pow(2.0, (double)number); number = tataku(eat); } else if ((eat - (long long)pow(2.0, (double)number)) > 0) { number2 += number; if (number == 0)break; eat -= (int)pow(2.0, (double)number); number = tataku(eat); }; } cout << number2 << "\n"; }