筛选因子不能用普通的筛法(这种方法会TLE),要利用筛因子法利用逆向思维,枚举因子的倍数反向加入到i中。
#include<bits/stdc++.h>
#define ll long long
#define MOD 10e9
#define INF 999999999
const int MAX = 505;
const int INFTY = (1 << 21);
using namespace std;
ll n, ai, m;
ll a[2000006];
ll b[2000006];
int main() {
// freopen("data.out", "w", stdout);
scanf("%lld %lld %lld", &n, &ai, &m);
a[1] = ai;
for(int i = 2; i <= n; ++i) {
a[i] = (a[i - 1] + 7 * i) % m;
}
for(int i = 1; i <= n; ++i) {
for(int j = i; j <= n; j += i)
b[j] += a[i];
}
int tot = 0;
for(int i = 1; i <= n; ++i) {
tot ^= b[i];
}
printf("%lld\n", tot);
return 0;
}