#include <stdio.h> int countSetBits(unsigned int n) { int count; while (n) { n &= (n - 1); //keeps all set bits except the rightmost. count++; } return count; } int main() { int n; scanf("%d", &n); printf("%d", countSetBits(n)); return 0; }