Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <set>
  4. #include <vector>
  5.  
  6. using namespace std;
  7.  
  8. bool nin(int x, set <int> s) {
  9.     return s.find(x) == s.end();
  10. }
  11.  
  12. int main() {
  13.     int t, j;
  14.     cin >> t;
  15.     for (j = 0; j < t; j++){
  16.     int n, x, k = 0, s = 0;
  17.     vector <int> v;
  18.     set <int> a;
  19.     cin >> n;
  20.     for (int i = 0; i < n; i++) {
  21.         cin >> x;
  22.         a.insert(x);
  23.     }
  24.     for (auto f : a) {
  25.         if (f % 2 == 0) {
  26.             s++;
  27.             v.push_back(f);
  28.         }
  29.     }
  30.     for (int i = s - 1; i >= 0; i--) {
  31.         x = v[i];
  32.         x /= 2;
  33.         k++;
  34.         while (nin(x, a) && x % 2 == 0) {
  35.             x /= 2;
  36.             k++;
  37.         }
  38.         a.erase(v[i]);
  39.     }
  40.     cout << k << endl;
  41.     }
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement