How to use the bit operations to find the number of units with running time O (k),
k - number of units in binary notation?
int n, ans;
cin >> n;
while (n) {
if (n & 1) {
ans++;
}
n = (n >> 1);
}
cout << ans;
Time complexity of my solution is O(log n). But I need O(k).