Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- int main(int argc, char const *argv[])
- {
- int n;
- cin >> n;
- int a[n];
- for (int i = 0; i < n; ++i)
- {
- cin >> a[i];
- }
- int sum = 0, count =0;
- for (int i = 0; i < 32; ++i)
- {
- //Since we know for a fact that there are 3x+1 numbers,
- //count the number of occureces of 1s per bit. If the outlier
- //has the ith bit set, then count%3 won't be 0, if the outlier's
- //ith bit is set, then count%3 for that bit will be 0.
- count = 0;
- for (int j = 0; j < n; ++j)
- {
- count += (1<<i) & a[j];
- }
- count = count % 3;
- sum += (count<<i);
- //cout << count << endl;
- }
- cout << sum << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment