算式子
算式子
https://ac.nowcoder.com/acm/contest/211/F
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6 + 10;
ll ans1[N], ans2[N], cnt[N], sum[N];
int n, m;
void init() {
for (int i = 1; i <= m; i++) {
for (int j = i; j <= m; j += i) {
int r = min(j + i - 1, m), l = j;
ans1[i] += 1ll * (cnt[r] - cnt[l - 1]) * (j / i);
ll res = 1ll * (j / i) * (cnt[i] - cnt[i - 1]);
ans2[l] += res;
ans2[r + 1] -= res;
}
}
for (int i = 1; i <= m; i++) {
ans2[i] += ans2[i - 1];
}
}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
cnt[x]++;
}
for (int i = 1; i <= m; i++) {
cnt[i] += cnt[i - 1];
}
init();
ll ans = 0;
for (int i = 1; i <= m; i++) {
ans ^= (ans1[i] + ans2[i]);
}
printf("%lld\n", ans);
return 0;
}
查看14道真题和解析
数字马力公司福利 22人发布