题目链接
求: ∑ i = 1 A ∑ j = 1 B ∑ k = 1 C d ( i j k ) \sum_{i=1}^A\sum_{j=1}^B\sum_{k=1}^Cd(ijk) i=1∑Aj=1∑Bk=1∑Cd(ijk)
其中 d ( i ) d(i) d(i)为 i i i的因数个数。 A , B , C ≤ 1 0 5 A,B,C\le 10^5 A,B,C≤105
居然真的会有这么美妙的结论qwq……
d ( i j k ) = ∑ a ∣ i ∑ b ∣ j ∑ c ∣ k [ gcd ( a , b ) = 1 ] [ gcd ( a , c ) = 1 ] [ gcd ( b , c ) = 1 ] d(ijk)=\sum_{a|i}\sum_{b|j}\sum_{c|k}[\gcd(a,b)=1][\gcd(a,c)=1][\gcd(b,c)=1] d(ijk)=a∣i∑b∣j∑c∣k∑[gcd(a,b)=1][gcd(a,c)=1][gcd(b,c)=1]
感性理解一下就是,每个质因数分开考虑。假设它在 i , j , k i,j,k i,j,k中的指数分别为 x , y , z x,y,z x,y,z,那么它总共会在上面的算式中出现恰好 x + y + z + 1 x+y+z+1 x+y+z+1次。由于所有质数贡献独立,因此上面的算式就等于因数个数。
暴力带入原式并使用莫比乌斯反演,可以得到:
∑ i = 1 A ∑ j = 1 B ∑ k = 1 C ∑ a ∣ i ∑ b ∣ j ∑ c ∣ k ∑ x ∣ a , x ∣ b μ ( x ) ∑ y ∣ a , y ∣ c μ ( y ) ∑ z ∣ b , z ∣ c μ ( z ) = ∑ i = 1 A ∑ j = 1 B ∑ k = 1 C ∑ x ∣ i , x ∣ j ∑ y ∣ i , y ∣ k ∑ z ∣ j , z ∣ k μ ( x ) μ ( y ) μ ( z ) d ( i l c m ( x , y ) ) d ( j l c m ( x , z ) ) d ( k l c m ( y , z ) ) = ∑ x = 1 A ∑ y = 1 A ∑ z = 1 B μ ( x ) μ ( y ) μ ( z ) D ( A l c m ( x , y ) ) D ( B l c m ( x , z ) ) D ( C l c m ( y , z ) ) \sum_{i=1}^A\sum_{j=1}^B\sum_{k=1}^C\sum_{a|i}\sum_{b|j}\sum_{c|k}\sum_{x|a,x|b}\mu(x)\sum_{y|a,y|c}\mu(y)\sum_{z|b,z|c}\mu(z) \\ =\sum_{i=1}^A\sum_{j=1}^B\sum_{k=1}^C\sum_{x|i,x|j}\sum_{y|i,y|k}\sum_{z|j,z|k}\mu(x)\mu(y)\mu(z)d\left(\frac{i}{lcm(x,y)}\right)d\left(\frac{j}{lcm(x,z)}\right)d\left(\frac{k}{lcm(y,z)}\right) \\ =\sum_{x=1}^A\sum_{y=1}^A\sum_{z=1}^B\mu(x)\mu(y)\mu(z)D\left(\frac{A}{lcm(x,y)}\right)D\left(\frac{B}{lcm(x,z)}\right)D\left(\frac{C}{lcm(y,z)}\right) i=1∑Aj=1∑Bk=1∑Ca∣i∑b∣j∑c∣k∑x∣a,x∣b∑μ(x)y∣a,y∣c∑μ(y)z∣b,z∣c∑μ(z)=i=1∑Aj=1∑Bk=1∑Cx∣i,x∣j∑y∣i,y∣k∑z∣j,z∣k∑μ(x)μ(y)μ(z)d(lcm(x,y)i)d(lcm(x,z)j)d(lcm(y,z)k)=x=1∑Ay=1∑Az=1∑Bμ(x)μ(y)μ(z)D(lcm(x,y)A)D(lcm(x,z)B)D(lcm(y,z)C)
其中 D ( i ) = ∑ j = 1 i d ( i ) D(i)=\sum_{j=1}^id(i) D(i)=∑j=1id(i)。
考虑 x , y , z x,y,z x,y,z全都不相等的情况。我们可以建无向图,对于任意的 x < y , l c m ( x , y ) ≤ C x<y,lcm(x,y)\le C x<y,lcm(x,y)≤C,连边 ( x , y ) (x,y) (x,y)。然后找图中的三元环,并任意轮换3!次加入答案。
如果 x , y , z x,y,z x,y,z中恰好有一对相等,则可以任意轮换3次计入答案。
如果全部相等,直接循环枚举即可。
三元环计数在本题中似乎暴力就能过(大雾)。
#include
namespace IOStream {
const int MAXR = 1 << 23;
char _READ_[MAXR], _PRINT_[MAXR];
int _READ_POS_, _PRINT_POS_, _READ_LEN_;
inline char readc() {
#ifndef ONLINE_JUDGE
return getchar();
#endif
if (!_READ_POS_) _READ_LEN_ = fread(_READ_, 1, MAXR, stdin);
char c = _READ_[_READ_POS_++];
if (_READ_POS_ == MAXR) _READ_POS_ = 0;
if (_READ_POS_ > _READ_LEN_) return 0;
return c;
}
template<typename T> inline void read(T &x) {
x = 0; register int flag = 1, c;
while (((c = readc()) < '0' || c > '9') && c != '-');
if (c == '-') flag = -1; else x = c - '0';
while ((c = readc()) >= '0' && c <= '9') x = x * 10 + c - '0';
x *= flag;
}
template<typename T1, typename ...T2> inline void read(T1 &a, T2 &...x) {
read(a), read(x...);
}
inline int reads(char *s) {
register int len = 0, c;
while (isspace(c = readc()) || !c);
s[len++] = c;
while (!isspace(c = readc()) && c) s[len++] = c;
s[len] = 0;
return len;
}
inline void ioflush() {
fwrite(_PRINT_, 1, _PRINT_POS_, stdout), _PRINT_POS_ = 0;
fflush(stdout);
}
inline void printc(char c) {
_PRINT_[_PRINT_POS_++] = c;
if (_PRINT_POS_ == MAXR) ioflush();
}
inline void prints(char *s) {
for (int i = 0; s[i]; i++) printc(s[i]);
}
template<typename T> inline void print(T x, char c = '\n') {
if (x < 0) printc('-'), x = -x;
if (x) {
static char sta[20];
register int tp = 0;
for (; x; x /= 10) sta[tp++] = x % 10 + '0';
while (tp > 0) printc(sta[--tp]);
} else printc('0');
printc(c);
}
template<typename T1, typename ...T2> inline void print(T1 x, T2... y) {
print(x, ' '), print(y...);
}
}
using namespace IOStream;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define cls(a) memset(a, 0, sizeof(a))
const int MAXN = 100005, MOD = 1000000007;
int mu[MAXN], prime[MAXN], vis[MAXN], A, B, C = 100000, T;
ll d[MAXN], da[MAXN], db[MAXN], dc[MAXN];
vector<P> g[MAXN];
int main() {
mu[1] = 1;
for (int i = 2, cnt = 0; i <= C; i++) {
if (!vis[i]) mu[prime[++cnt] = i] = -1;
for (int j = 1; j <= cnt; j++) {
int p = prime[j], q = i * p;
if (q > C) break;
vis[q] = 1;
if (i % p == 0) break;
mu[q] = -mu[i];
}
}
for (int i = 1; i <= C; i++) {
for (int j = i; j <= C; j += i) ++d[j];
d[i] += d[i - 1];
}
for (scanf("%d", &T); T--;) {
scanf("%d%d%d", &A, &B, &C);
cls(vis);
if (A > B) swap(A, B);
if (A > C) swap(A, C);
if (B > C) swap(B, C);
for (int i = 1; i <= C; i++) {
da[i] = d[A / i];
db[i] = d[B / i];
dc[i] = d[C / i];
g[i].clear();
}
ll ans = 0;
for (int i = 1; i <= C; i++) {
for (int j = 1; j * i <= C; j++) {
for (int k = j + 1; (ll)i * j * k <= C; k++) {
int a = i * j, b = i * k, c = i * j * k;
if (!mu[a] || !mu[b] || __gcd(j, k) > 1) continue;
ans += mu[a] * mu[a] * mu[b] * (
da[c] * db[c] * dc[a] +
da[c] * db[a] * dc[c] +
da[a] * db[c] * dc[c] );
ans += mu[a] * mu[b] * mu[b] * (
da[b] * db[c] * dc[c] +
da[c] * db[b] * dc[c] +
da[c] * db[c] * dc[b] );
g[a].push_back(P(b, c));
}
}
ans += mu[i] * mu[i] * mu[i] * da[i] * db[i] * dc[i];
}
for (int i = 1; i <= C; i++) if (mu[i]) {
for (P j : g[i]) vis[j.first] = i, prime[j.first] = j.second;
for (P j : g[i]) if (j.first > i && mu[j.first]) {
int a = j.second;
for (P k : g[j.first]) if (k.first > j.first && vis[k.first] == i && mu[k.first]) {
int b = k.second, c = prime[k.first];
ans += mu[i] * mu[j.first] * mu[k.first] * (
da[a] * db[b] * dc[c] +
da[a] * db[c] * dc[b] +
da[b] * db[a] * dc[c] +
da[b] * db[c] * dc[a] +
da[c] * db[a] * dc[b] +
da[c] * db[b] * dc[a] );
}
}
}
printf("%lld\n", (ans % MOD + MOD) % MOD);
}
return 0;
}