按位运算的小技巧, n & =(n-1)可以消除最末尾的一
#include <iostream>
void solve() {
int n, cnt = 0;
std::cin >> n;
while (n) {
n = n & (n - 1);
cnt++;
}
std::cout << cnt << std:: endl;
}
int main() {
solve();
return 0;
}
/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⡀⡀⡀⠀⠀⠀⠀⢰⢰⡶⣼⣲⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⢰⣪⡠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⣶⢶⢶⡶⣮⣕⡤⠀⠠⢼⢸⢧⢫⡫⣷⡐⡀⠀⢀⣢⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠜⣞⣽⣊⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⢜⢷⢵⣒⣒⡱⣟⣿⡻⠯⡟⣯⡧⡷⢸⣵⡱⡎⡾⡽⣳⡑⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡇⣟⣞⣗⡎⡆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠑⠭⣛⣺⣫⡟⠗⠽⢬⢽⣱⡻⡫⣷⢯⡷⡧⣟⡏⣎⢟⡎⣦⡭⣅⠄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⢱⣳⡯⣷⢯⠸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠙⡚⠟⠯⠿⢽⡺⣞⡋⣋⣛⢙⣫⢛⣽⡸⢸⡇⢱⡇⣝⢟⣌⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡌⣼⣺⢯⣿⢽⡅⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠉⠀⠈⠊⡻⢵⡦⣖⡮⣟⠜⣛⢽⡾⣮⢿⡸⡊⣯⡜⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡐⣔⣗⣿⢽⡾⣯⠆⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠑⠒⠒⠊⡅⡭⡬⡵⡽⣽⣻⣞⡆⣯⢰⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣀⠀⠀⠀⢀⢆⣞⡾⣽⣽⣽⣟⣗⡇⡃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠃⢻⡪⠁⠈⢅⢟⣾⣺⣽⢘⠠⣪⡥⣤⢠⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠠⢲⣲⢕⡀⢠⢡⣗⣯⣿⣻⣺⣿⣺⣽⠰⠀⠀⠀⠀⠀⠠⠀⢀⣠⣤⡶⣶⢷⡿⣾⡶⣦⣈⠀⠀⠀⠐⣀⣀⡀⡂⠠⠀⠀⠀⠀⠀⠀⠀⠁⢸⡀⢀⢎⢷⣻⣞⣨⡞⡣⡙⣟⢸⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⡃⣗⣯⢷⡁⣗⣯⡷⣿⣺⢿⡾⣽⡗⡘⡀⠄⠀⢀⣠⣴⣾⢿⣯⣷⡿⣟⡿⣻⡫⣟⢿⣻⡿⣶⣞⣿⣯⣷⢿⣻⡷⣦⣄⡀⠀⠀⠀⠀⠀⢸⣿⣄⠋⠛⣖⣟⣾⢁⢣⢣⣟⢸⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢰⢸⣞⣯⣟⡾⣽⡯⣿⣞⣿⣯⢷⣷⢶⣦⣬⡰⢿⣽⣟⣾⢿⡷⡿⣝⣝⢮⣣⢯⣪⣏⣯⡿⣷⢯⣣⣳⡹⣝⢿⣻⣯⣿⣻⣷⣄⡀⠠⡐⠀⢿⣿⣆⠁⣿⡺⣯⢘⣵⡻⡢⠃⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢸⢸⣺⡷⣯⣟⣷⢿⣯⣷⣟⣾⡿⢡⡭⡮⣮⣭⢢⣷⣟⣯⢿⣹⣺⣞⣾⣯⣿⣻⣯⣿⣳⣿⣻⣟⣿⢷⡿⣮⣗⣝⢷⡿⣽⡾⣯⣷⠎⣿⣷⣌⢿⣿⣧⠘⠹⢸⣳⢱⠋⡄⣂⣥⢀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⡌⡼⣗⣿⣗⣿⣽⣟⣷⣟⣯⣿⣟⢸⣿⣿⣝⡏⢾⣷⢻⣵⢿⣽⣯⣟⣷⢿⣞⣿⢾⡷⣿⣽⢯⣟⡾⣟⣿⣽⡾⣷⣗⡟⣿⣻⣯⢿⣯⠜⣿⣿⣷⣯⣿⡆⢀⠸⣯⢾⢻⢽⢫⡟⡨⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢣⢻⡿⣗⣿⢷⣿⣽⠯⢟⢹⣷⡯⣺⣿⣿⡿⣿⡦⢳⣟⣿⣟⣷⣯⡿⣾⣟⣯⡿⣯⣿⣻⡾⣟⣿⣞⢿⣽⡾⣟⣿⡾⣿⢽⣽⣾⣟⣯⣿⣬⠻⣿⣿⣿⡿⠐⣯⢯⠘⢁⢇⢾⢁⠃⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠈⠪⠻⣻⡿⠻⣩⡦⣿⣽⣳⣌⠗⣺⣿⡿⣿⡟⣱⣿⣻⣟⣿⡿⣾⣿⣯⢿⣽⣻⡿⣾⢯⣿⣟⣷⣿⣝⣷⣿⣿⡿⣟⣿⣯⣷⢿⣾⣻⡷⣟⣿⣆⡛⢿⣟⠠⣟⡼⣭⢵⠝⠣⠂⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠤⢀⣀⢠⠨⣠⡾⢯⣳⣽⣽⡳⣿⡮⣇⢻⣿⡿⢋⣼⡿⣾⢯⣿⡿⣿⣿⣻⣞⣿⣟⣿⡿⣿⡿⣿⣽⣿⣾⣷⣻⣿⣽⣿⣟⣷⢿⡾⣿⣽⢷⡿⣿⣽⣾⢷⣑⢿⠀⣯⢇⣖⡒⠁⠀⠀⡄⣤⢠⠀⠀⠀⠀
⠀⠀⠀⠰⡰⣻⢲⢶⣤⢘⣯⣾⣿⡻⣝⣻⣽⡺⣿⣻⢦⠍⣶⡿⣯⣟⣿⣻⣽⣿⢿⣯⣟⣾⣿⢿⣻⣿⡿⣿⣿⣻⣽⣷⣿⣺⣿⣟⣷⢿⣽⣟⣿⣽⡾⣿⣻⣟⡾⣽⣟⣿⣆⢢⠘⠩⢑⡿⢝⠘⢜⣜⣷⢮⡢⠀⠀⠀
⠀⠀⠀⠀⢁⢻⣆⢷⠊⠠⡻⣯⣗⣯⣿⡿⣺⡿⣮⣻⡝⣼⣟⣿⣻⢮⣷⣿⣽⣾⢿⣟⣾⣿⢿⣿⣿⣟⣿⣿⣻⣿⢿⣻⣷⢫⢻⣾⣟⡿⡧⡿⣷⣻⣟⣯⣿⡽⣿⣮⡻⣾⣻⣶⠱⡀⠋⠃⠊⠀⣟⢽⣾⡻⣹⠈⠀⠀
⠀⠀⡀⣲⣵⡳⠽⠽⠳⠸⣟⡾⣽⣾⢾⣣⢿⡽⣯⠚⣴⢿⡾⣯⣗⡿⣷⢿⣞⣯⣟⣮⣿⣻⡿⣿⣾⡿⣟⣯⣿⡿⣿⣟⡇⡾⡌⢷⣟⣿⣻⢽⡿⣽⣯⢿⣾⣻⣟⣾⢷⡹⣟⣾⣯⡚⣄⠠⠀⠀⠘⡌⡾⢱⠀⠀⠀⠀
⠀⠊⠞⢯⡦⣜⡣⠭⠥⠈⢽⡽⣾⢵⢿⣪⢿⡽⣡⣿⣻⣯⣿⣻⢮⣿⣻⢯⢿⢽⢺⡺⣷⣟⣿⣽⡾⣟⣿⣻⣽⠝⣷⣫⡃⣭⣧⡩⣻⢽⣻⢵⡿⣟⣾⣟⣷⢿⣽⡮⢿⡽⡜⢿⡾⣷⡩⣆⠀⠀⠀⠀⠂⠀⠀⠀⠀⠀
⠀⠀⠈⠑⠒⠭⣚⠟⠾⢋⢀⡮⢢⣶⢮⣭⣹⣰⢿⣽⣗⢷⡿⣽⢺⣳⣽⣟⡿⠁⣼⡿⣽⢾⣻⣾⣻⢿⣽⢯⡟⠨⣟⡯⢸⣿⣿⣷⡌⢿⣻⡵⣿⣗⣽⡾⣟⣿⡽⣟⢼⢯⣻⢜⣻⣽⣷⡘⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢙⣡⠃⣼⢪⣻⣽⣟⣗⡷⣟⣯⣷⢯⣻⢿⡽⣽⣳⢿⡞⣡⠇⣯⠏⣾⣟⣿⣞⡿⣯⣻⡟⡡⢸⡿⢰⣿⣿⣿⢿⣿⣦⠻⢝⣷⡣⣷⢿⣻⡷⣿⢿⡪⡇⣳⣫⢪⢳⣟⣧⢱⣟⡶⣀⠀⠠⠀⠀⠀⠀
⠀⠀⠀⠀⢀⢀⢢⣖⡗⢨⢇⣾⣟⣷⡻⣼⣟⣯⡿⣾⡳⣻⣟⣗⣳⣯⠟⣰⣻⡌⠗⡌⣯⡿⣞⣷⢿⣳⠟⣰⠏⠞⣡⣿⣻⣽⣽⣿⣿⣿⡷⢸⡻⠘⣾⣟⣯⡿⣯⢿⡪⣯⠘⡚⠕⠍⣿⣻⡅⠓⠟⠽⠛⠑⠀⠀⠀⠀
⠀⠀⢀⢠⣢⣞⣗⠷⠁⡏⣾⣽⢾⡏⣞⣿⣺⡯⣿⡽⣗⢽⣷⣳⠳⢃⠾⠽⠻⠂⠟⢧⣓⣝⣙⣭⣍⣦⣾⣟⣤⣿⣿⡿⠛⠉⢈⠀⠠⠀⡁⡵⢃⠪⣟⣾⡳⣿⢽⣟⢎⣾⡊⡿⢟⣷⡘⣿⡧⠈⠐⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢐⠐⠀⠂⠈⠀⡵⣟⣾⡻⣸⡽⣞⣵⢿⣳⣟⣷⢹⡾⣇⠂⠄⠂⢐⣈⣄⣔⣀⣈⢹⣿⣿⣿⣿⣿⣿⣿⣿⣯⣤⣶⣷⣶⣷⣷⡶⢰⢉⠄⢼⢽⡳⣽⢯⡿⣽⢸⣽⡆⣺⣿⣿⣇⢳⣟⠀⠂⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⡀⢰⣟⣯⡟⢼⢵⣻⢕⣯⢿⡽⣞⣯⡧⡻⣮⡐⣰⣾⡿⣿⣟⣿⣿⣿⣿⣿⣿⣯⣿⣿⣻⣽⣾⣿⣿⣯⣷⡿⣷⢿⠃⣅⣾⢃⡿⣝⡾⣯⢿⡽⡏⡮⣷⡗⠸⡛⢉⠁⠨⡯⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢠⣟⣷⡻⠪⣯⣻⡺⢼⡯⣿⢽⡝⣷⣻⡎⠳⣇⠹⣷⡿⣿⣽⣟⣾⣯⣿⣷⣿⣿⣿⣾⣿⣿⣿⣿⣷⣿⣳⣿⣯⣿⣾⣽⠋⡼⡽⣞⣯⢿⡽⣽⢣⣟⡷⡯⢘⡧⠀⠀⠀⡏⠈⠀⠀⠠⡰⡄⡄⠀⠀
⠀⠀⠀⠀⠀⠀⠁⣾⣳⢯⠃⢸⣳⡳⡏⢳⢿⢽⢯⣟⡮⡷⣯⠰⣍⠣⠹⣟⣷⡿⣷⢿⣻⣿⡿⣿⢬⢭⣝⡵⣕⣺⣿⣿⣾⣿⣆⠬⣬⡬⣴⣺⢯⡿⣽⣞⣯⢯⢇⣗⣷⡻⡯⢘⣞⠄⠀⠀⠀⠁⠀⠀⠐⠑⠇⠂⠀⠀
⠀⠀⠀⠀⠀⡀⢸⣗⣯⠏⠀⢸⢮⢯⡃⠨⣟⣯⣟⡾⣽⣳⢽⣱⠙⢿⣷⣾⣿⢿⣿⣿⣿⣿⣿⣿⡇⣟⣞⢾⡕⣾⣿⣯⣿⣿⣻⣷⣌⡋⠷⠯⠯⡟⣞⣞⡞⡏⡆⣳⣗⣟⡯⢢⢳⣣⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣟⡾⣺⠁⠀⠨⡯⣯⠂⡀⢻⣞⢾⢽⣳⢯⣟⣞⣟⡶⡦⣦⠒⣴⣿⣿⣟⣯⣿⣿⣿⣜⣞⣗⣧⣿⣷⣿⣿⣿⣿⠿⠟⢋⢴⢽⢣⣳⢗⠏⣼⣺⡳⢸⣺⣺⡝⢨⢧⢳⢕⠐⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣷⡻⡇⠀⠀⠀⢹⢮⡃⠐⠈⢞⣧⡻⡚⠗⠷⡳⠗⠏⣋⡔⡦⡍⡍⡛⠛⠿⠿⠿⠯⡿⠿⠿⠿⠻⠛⡛⣙⡡⡥⡒⣡⣾⣙⠜⡕⢕⡱⡨⡲⢆⣝⢸⣺⣺⠅⠈⢮⢳⢝⢖⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢳⢯⡃⠀⠀⠀⢀⠹⡦⠀⢠⢧⣓⠯⢷⣘⢳⣾⣾⣎⡱⢙⠸⡝⡮⢋⣋⣃⣒⠳⠖⡔⣼⢦⢑⠾⣷⠘⣊⡚⢊⣴⢿⢞⡿⣜⢙⡊⠮⠎⣆⠹⡎⣸⢞⡎⠠⠀⠀⠉⠺⢵⡹⣢⡀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠈⢻⡆⠀⠀⠀⠀⠀⠈⠣⢸⣿⣺⢁⢦⠰⣴⣶⡿⣿⣿⣶⡤⠌⣰⣿⡽⣯⡿⣃⠯⡿⣺⡽⣞⠗⣴⣬⢻⠋⣼⢞⡯⡽⢋⡔⣗⢽⡹⡝⡮⣢⠁⡾⠝⣠⠀⠀⠀⠀⠀⠀⠌⠈⠈⠁⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠰⢘⣆⢀⠠⠙⠂⠀⠀⠀⠀⠀⣰⣶⢿⠃⡼⣕⢧⡘⢿⣿⣷⡄⠰⣶⣎⣦⠹⡛⢝⣴⢹⡘⠯⡚⡳⠳⡨⣬⡩⠒⢱⢯⣻⠘⡁⣞⢮⡳⡳⣝⢮⣫⢊⢈⠨⣞⣿⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠰⣱⢵⡳⣪⡁⠄⠀⠀⠀⠀⡀⣰⣿⠽⢡⡺⣝⢮⡳⣝⡄⢿⣿⡃⣂⣪⣟⢟⠥⠗⣛⣅⣍⡫⢿⢽⢽⢝⣱⣨⡛⠫⠸⣽⡺⢠⢐⢳⡳⣝⢵⡳⣳⢳⢝⡽⣕⡌⠿⣧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢢⠳⡝⠰⠂⠀⠀⠀⠀⠀⣰⠟⢉⢴⡳⣝⢮⡳⣝⢮⠮⢸⡿⢰⡿⣟⠻⡜⣡⡟⣧⢽⡸⡒⢮⢉⠴⠪⢎⣧⣛⣻⣄⠘⢗⠸⣿⣧⢬⡚⢵⡫⣞⢽⢕⡯⣞⢞⣦⡙⠧⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠈⠃⠀⠀⠀⠀⢀⠈⠈⠁⠰⡱⡯⡺⢕⠯⡚⡎⠥⠖⠨⢐⣴⡴⣢⣧⢣⣿⣿⢺⡟⢼⣟⡳⣫⢳⡂⡈⢷⣏⣾⣿⡌⣦⢥⣦⣦⡂⠿⠦⡍⠺⢝⢳⢫⠾⢝⢞⡞⡦⠄⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠡⠅⠌⠌⠐⠐⠀⠀⡚⠯⡯⠸⣿⣷⣿⢾⣗⣿⠿⠿⠿⠶⠌⡺⠸⢕⠡⠶⠿⠿⠿⢏⣞⣝⣷⣻⣿⠇⡽⡕⠗⠠⠐⠈⠀⠥⠅⠅⠌⠊⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠍⠑⢈⠛⠛⠣⡃⡁⠀⠀⠀⠀⠀⠈⠁⠀⠀⠀⠀⠀⠐⠈⠈⠓⠻⠊⠃⠘⠌⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
*/

京公网安备 11010502036488号