H xay loves count

题意

在数组 中找满足 的三元组

暴力即可(看似是 ​ 但不是)

#include <bits/stdc++.h>
using namespace std;
#define rep(i, j, k) for (ll(i) = (j); (i) <= (k); (++i))
typedef long long ll;
const int N = 1e6 + 7;
ll a[N];
signed main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, x, mx = 0;
    cin >> n;
    rep(i, 1, n) {
        cin >> x;
        a[x]++;
        mx = max(mx, x);
    }
    ll ans = 0;
    rep(i, 1, mx) {
        rep(j, i, mx) {
            ll x = i * j;
            if (x > mx)
                break;
            ans += a[i] * a[j] * a[x] * (j == i ? 1 : 2);
        }
    }
    cout << ans << '\n';
    return 0;
}

I xay loves or

题意

问存在多少个 使得

逐个按位讨论即可

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int ll
#define rep(i, j, k) for (ll(i) = (j); (i) <= (k); (++i))
typedef long long ll;
signed main() {
    int x, s;
    cin >> x >> s;
    if (x > s)
        return cout << 0 << endl, 0;
    int ans = 1;
    rep(i, 0, 30) {
        if (!((s >> i) & 1) and ((x >> i) & 1))
            return cout << 0 << endl, 0;
        if (((s >> i) & 1) and ((x >> i) & 1))
            ans <<= 1;
    }
    cout << ans - (x == s) << endl;
    return 0;
}