십진수를 이진수로 바꾸면서 1인 자릿수의 개수를 구하면 된다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(void)
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int X, count = 1;
//64cm막대로 X길이의 막대 만들기
cin >> X;
//2진법이랑 비슷한듯?
//이진수에서 1의 갯수를 구하면 된다...
while (1)
{
//cout << X << "\n";
if (X == 1 || X == 0)
{
break;
}
else if (X % 2 == 1)
{
X = X / 2;
count++;
}
else
{
X = X / 2;
}
}
cout << count << "\n";
return 0;
}