1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| #include<bits/stdc++.h> #define Pair pair<int, int> #define MP make_pair #define fi first #define se second #define LL long long
const int MAXN = 2e5 + 10, mod = 1e9 + 7; using namespace std; template <typename A, typename B> inline bool chmin(A &a, B b){if(a > b) {a = b; return 1;} return 0;} template <typename A, typename B> inline bool chmax(A &a, B b){if(a < b) {a = b; return 1;} return 0;} template <typename A, typename B> inline LL add(A x, B y) {if(x + y < 0) return x + y + mod; return x + y >= mod ? x + y - mod : x + y;} template <typename A, typename B> inline void add2(A &x, B y) {if(x + y < 0) x = x + y + mod; else x = (x + y >= mod ? x + y - mod : x + y);} template <typename A, typename B> inline LL mul(A x, B y) {return 1ll * x * y % mod;} template <typename A, typename B> inline void mul2(A &x, B y) {x = (1ll * x * y % mod + mod) % mod;} inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') {if(c == '-') f = -1; c = getchar();} while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int mu[MAXN], prime[MAXN], vis[MAXN], tot, A, B, C, num, deg[MAXN]; int fa[MAXN], fb[MAXN], fc[MAXN]; vector<LL> di[MAXN]; vector<Pair> v[MAXN]; struct Edge { LL u, v, w; }E[MAXN * 10]; void GetPrime(int N) { vis[1] = 1; mu[1] = 1; for(int i = 2; i <= N; i++) { if(!vis[i]) prime[++tot] = i, mu[i] = -1; for(int j = 1; j <= tot && i * prime[j] <= N; j++) { vis[i * prime[j]] = 1; if(i % prime[j]) mu[i * prime[j]] = -mu[i]; else {mu[i * prime[j]] = 0; break;} } } for(int i = 1; i <= tot; i++) for(int j = 1; j * prime[i] <= N; j++) di[j * prime[i]].push_back(prime[i]); }
void Get(int *a, int N, int X) { for(int i = 1; i <= N; i++) for(int j = i; j <= N; j += i) a[i] += X / j; } LL lcm(int a, int b) { return 1ll * a / __gcd(a, b) * b; } void init() { memset(fa, 0, sizeof(fa)); memset(fb, 0, sizeof(fb)); memset(fc, 0, sizeof(fc)); memset(deg, 0, sizeof(deg)); num = 0; for(int i = 1; i <= A; i++) v[i].clear(); } void Build() { for(int w = 1; w <= A; w++) { if(!mu[w]) continue; int n = di[w].size(); for(int sta = 0; sta < (1 << n); sta++) { LL i = 1; for(int b = 0; b < n; b++) if(sta >> b & 1) i *= di[w][b]; for(int s = sta; ; s = sta & (s - 1)) { LL g = 1; for(int b = 0; b < n; b++) if(s >> b & 1) g *= di[w][b]; int j = w * g / i; if(i < j) E[++num] = {i, j, w}; if(!s) break; } } } }
LL fuck(int x, int y, int w) { if(mu[x] == 1) return add(add(mul(mul(fa[w], fb[w]), fc[y]), mul(mul(fa[w], fb[y]), fc[w])), mul(mul(fa[y], fb[w]), fc[w])); else return (-add(add(mul(mul(fa[w], fb[w]), fc[y]), mul(mul(fa[w], fb[y]), fc[w])), mul(mul(fa[y], fb[w]), fc[w])) + mod) % mod; }
LL calc() {
for(int i = 1; i <= num; i++) { int x = E[i].u, y = E[i].v; if(deg[x] > deg[y]) swap(x, y); v[y].push_back(MP(x, E[i].w)); } LL ans = 0; for(int a = 1; a <= A; a++) { for(auto &t1 : v[a]) { LL b = t1.fi, w1 = t1.se; for(auto &t2 : v[b]) { LL c = t2.fi, w2 = t2.se, xi = mu[a] * mu[b] * mu[c]; LL w3 = lcm(a, c); if(w3 > A) continue; if(xi == 1) { add2(ans, mul(mul(fa[w1], fb[w2]), fc[w3])); add2(ans, mul(mul(fa[w1], fb[w3]), fc[w2])); add2(ans, mul(mul(fa[w2], fb[w1]), fc[w3])); add2(ans, mul(mul(fa[w2], fb[w3]), fc[w1])); add2(ans, mul(mul(fa[w3], fb[w1]), fc[w2])); add2(ans, mul(mul(fa[w3], fb[w2]), fc[w1])); } else if(xi == -1) { add2(ans, mul(mul(-fa[w1], fb[w2]), fc[w3])); add2(ans, mul(mul(-fa[w1], fb[w3]), fc[w2])); add2(ans, mul(mul(-fa[w2], fb[w1]), fc[w3])); add2(ans, mul(mul(-fa[w2], fb[w3]), fc[w1])); add2(ans, mul(mul(-fa[w3], fb[w1]), fc[w2])); add2(ans, mul(mul(-fa[w3], fb[w2]), fc[w1])); } } } }
for(int i = 1; i <= num; i++) { add2(ans, fuck(E[i].u, E[i].v, E[i].w)); add2(ans, fuck(E[i].v, E[i].u, E[i].w)); } for(int i = 1; i <= C; i++) { if(mu[i] == 1) add2(ans, mul(mul(fa[i], fb[i]), fc[i])); else if(mu[i] == -1) add2(ans, -mul(mul(fa[i], fb[i]), fc[i]) + mod); } return ans; } void solve() { init(); A = read(); B = read(); C = read(); if(A < B) swap(A, B); if(C > B) swap(B, C); if(A < B) swap(A, B); Get(fa, A, A); Get(fb, A, B); Get(fc, A, C); Build(); cout << calc() << '\n'; } signed main() { GetPrime(2e5); for(int T = read(); T; T--, solve()); return 0; }
|