http://acm.hdu.edu.cn/showproblem.php?pid=6390
题意:求一个式子
题解:看题解,写代码
第一行就看不出来,后面的sigma公式也不会化简。mobius也不会
就自己写了个容斥搞一下(才能维持现在的生活)
//别人的题解https://blog.csdn.net/luyehao1/article/details/81672837
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include<ctime> using namespace std; const int maxn = 1e6 + 1000; typedef long long ll; ll F[maxn], phi[maxn], inv[maxn]; ll N, M, P; void init(int n) { for (int i = 1; i <= n; ++i) phi[i] = i; for (int i = 2; i <= n; ++i) { if (i == phi[i]) { for (int j = i; j <= n; j += i) phi[j] = phi[j] / i * (i - 1); } } } void init2(void) { inv[1] = 1; for (int i = 2; i <= N; ++i) inv[i] = (P - P / i * inv[P%i] % P) % P; for (int i = N; i; --i) { F[i] = 1ll * (N / i)*(M / i); // if(i == 1) cout<<F[i]<<endl; for (int j = i + i; j <= N; j += i) F[i] -= F [j]; } } int main() { int t; cin >> t; init(maxn-1); while (t--) { cin >>N>>M>>P; if (N < M)swap(N, M); init2(); ll ans = 0; for (ll i = 1; i <= N; ++i) { ans += (ll)i*inv[phi[i]] % P*(F[i] % P) % P; ans %= P; } cout << ans%P << endl; } } /* */