Guest User

Untitled

a guest
Jun 25th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4.  
  5. int main(int argc, char const *argv[])
  6. {
  7. int n;
  8. cin >> n;
  9. int a[n];
  10.  
  11. for (int i = 0; i < n; ++i)
  12. {
  13. cin >> a[i];
  14. }
  15. int sum = 0, count =0;
  16. for (int i = 0; i < 32; ++i)
  17. {
  18. //Since we know for a fact that there are 3x+1 numbers,
  19. //count the number of occureces of 1s per bit. If the outlier
  20. //has the ith bit set, then count%3 won't be 0, if the outlier's
  21. //ith bit is set, then count%3 for that bit will be 0.
  22. count = 0;
  23. for (int j = 0; j < n; ++j)
  24. {
  25. count += (1<<i) & a[j];
  26. }
  27. count = count % 3;
  28. sum += (count<<i);
  29. //cout << count << endl;
  30. }
  31.  
  32. cout << sum << endl;
  33. return 0;
  34. }
Add Comment
Please, Sign In to add comment