Advertisement
tien_noob

Chia hết cho 2^k (LQDOJ)

Feb 15th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <numeric>
  5. using namespace std;
  6. const int N = 2e5;
  7. int n, k;
  8. long long a[N+1], cnt = 0, b[65];
  9. void read()
  10. {
  11.    cin >> n >> k;
  12.    fill (b + 1, b + 65, 0);
  13.    for (int i = 1; i <= n; ++ i)
  14.    {
  15.        cin >> a[i];
  16.        int cnt = 0;
  17.        while (a[i] % 2 == 0)
  18.        {
  19.            ++cnt;
  20.            a[i]/=2;
  21.        }
  22.        a[i] = cnt;
  23.        ++b[cnt];
  24.    }
  25. }
  26. long long c3(long long x)
  27. {
  28.     return x*(x-1)*(x-2)/6;
  29. }
  30. long long c2 (long long x)
  31. {
  32.     return x*(x-1)/2;
  33. }
  34. void solve()
  35. {
  36.    for (int i = 0; i <= 64; ++ i)
  37.    {
  38.        for (int j = i + 1; j <= 64; ++ j)
  39.        {
  40.            for (int z = j + 1; z <= 64; ++ z)
  41.            {
  42.                if (i + j + z >= k)
  43.                {
  44.                    cnt += b[i] * b[j] * b[z];
  45.                }
  46.            }
  47.        }
  48.    }
  49.    for (int i = 0; i <= 64; ++ i)
  50.    {
  51.        for (int j = i + 1; j <= 64; ++ j)
  52.        {
  53.            if (2 * i + j >= k)
  54.            {
  55.                cnt += c2(b[i]) * b[j];
  56.            }
  57.            if (i + 2 * j >= k)
  58.            {
  59.                cnt += b[i] * c2(b[j]);
  60.            }
  61.        }
  62.    }
  63.    for (int i = 0; i <= 64; ++ i)
  64.    {
  65.        if (3 * i >= k)
  66.        {
  67.            cnt += c3(b[i]);
  68.        }
  69.    }
  70.    cout << cnt;
  71. }
  72. int main()
  73. {
  74.     ios_base::sync_with_stdio(false);
  75.     cin.tie(nullptr);
  76.     read();
  77.     solve();
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement