怎么最近做一题求助一题/kk
感觉应该挂的很离谱
#include <iostream>
#include <unordered_map>
using namespace std;
__int128 phi[2000005], phis1[2000005], p, inv2, inv6; unordered_map<long long, long long> phis2;
__int128 qp(__int128 n, __int128 m, __int128 p) {
__int128 ans = 1, base = n;
while (m) {
if (m & 1) (ans *= base) %= p;
(base *= base) %= p; m >>= 1;
}
return ans;
}
__int128 phisum(__int128 x) {
if (x < 2000000) return phis1[x];
if (phis2.count(x)) return phis2[x]; __int128 summ = (x * (x + 1) % p * inv2 % p) * (x * (x + 1) % p * inv2 % p) % p; __int128 l=2, r; while (l <= x) {r = x / (x / l); (((summ -= (r * (r + 1) % p * (2 * r + 1) % p * inv6 + p - (l-1) * l % p * (2 * (l-1) + 1) % p * inv6 % p) * phisum(x / l)) %= p) += p) %= p; l = r + 1;} phis2[x] = summ; return summ;
}
__int128 read() {long long x; cin >> x; return x;}
int main() {__int128 n, l=1, r, summ=0; p = read(); n = read();
for (int i=1; i<=2000000; i++) phi[i] = i;
for (int i=2; i<=2000000; i++) if (phi[i] == i) for (int j=i; j<=2000000; j+=i) phi[j] = (phi[j] / i) * (i - 1);
for (int i=1; i<=2000000; i++) (phi[i] *= (i * i) % p) %= p; for (int i=1; i<=2000000; i++) (phis1[i] = phis1[i-1] + phi[i]) %= p;
inv2 = qp(2, p-2, p); inv6 = qp(6, p-2, p); while (l <= n) {r = n / (n / l); (summ += (phisum(r) - phisum(l-1) + p) % p * ((n / l) * (n / l + 1) / 2 % p) * ((n / l) * (n / l + 1) / 2 % p) % p) %= p; l = r + 1;} cout << (long long)summ << endl;
}