CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <bitset>
using namespace std;
// find all non negative numbers smaller than 10000 that has odd number of 1 in its binary representation
int main() {
int count = 0;
for(auto i = 1; i < 10000; i++)
bitset<16>(i).count() & 1 ? count++ : true;
cout << count << endl;
return 0;
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run