莫反小練

Lu_xZ發表於2024-05-21

P1829 [國家集訓隊] Crash的數字表格 / JZPTAB

不妨假設 \(n < m\)

\[\begin{aligned} \sum_{i = 1}^n\sum_{j = 1}^m\dfrac{ij}{\gcd(i, j)} &= \sum_{d = 1}^n\sum_{i = 1}^n\sum_{j = 1}^m[\gcd(i, j) = d]\dfrac{ij}{d}\\ \\ &= \sum_{d = 1}^n\sum_{i = 1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j = 1}^{\lfloor\frac{m}{d}\rfloor}[\gcd(i, j) = 1]ijd\\ \\ &= \sum_{d = 1}^n\sum_{i = 1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j = 1}^{\lfloor\frac{m}{d}\rfloor}ijd\sum_{k \mid \gcd(i, j)}\mu(k)\\ \\ &= \sum_{d = 1}^n\sum_{k = 1}^{\lfloor\frac{n}{d}\rfloor}\mu(k)\cdot k^2\sum_{i = 1}^{\lfloor\frac{n}{dk}\rfloor}i\sum_{j = 1}^{\lfloor\frac{m}{dk}\rfloor}jd\\ \end{aligned} \]

定義 \(f(n) = \sum_{i = 1}^ni\)

列舉 \(T = dk\)

\[\begin{aligned} &= \sum_{d = 1}^n\sum_{k = 1}^{\lfloor\frac{n}{d}\rfloor}\mu(k)\cdot k^2f(\lfloor\frac{n}{dk}\rfloor)\cdot f(\lfloor\frac{m}{dk}\rfloor)\cdot d\\ \\ &= \sum_{T = 1}^{n}f(\lfloor\dfrac{n}{T}\rfloor)\cdot f(\lfloor\dfrac{m}{T}\rfloor)\cdot \sum_{d \mid T}\mu(\dfrac{T}{d})\cdot (\dfrac{T}{d})^2 \cdot d\\ \\ &= \sum_{T = 1}^{n}f(\lfloor\dfrac{n}{T}\rfloor)\cdot f(\lfloor\dfrac{m}{T}\rfloor)\cdot \sum_{d \mid T}\mu(d)\cdot d \cdot T\\ \end{aligned} \]

數論函式的積性在卷積中封閉。

由於 \(g(T) = \mu(T) \cdot T\) 是積性函式(\(id\) 完全積性,顯然成立),那麼 \(F(T) = \sum_{d \mid T}\mu(d)\cdot d = g * 1\) 也是積性函式。

即求

\[\sum_{T = 1}^{n}f(\lfloor\dfrac{n}{T}\rfloor)\cdot f(\lfloor\dfrac{m}{T}\rfloor)\cdot T\cdot F(T)\\ \]

可以線性篩預處理 \(T \cdot F(T)\) 的字首和,然後數論分塊。(對於函式 \(F\),任意質數的冪次 \(F(p^k) = 1 - p\)

P3327 [SDOI2015] 約數個數和

有結論

\[d(ij) = \sum_{x \mid i}\sum_{y\mid j}[\gcd(x, y) = 1] \]

假定 \(i = p_1^{a_1}p_2^{a_2}\cdots p_k^{a_k}, \ j = p_1^{b_1}p_2^{b_2}\cdots p_k^{b_k}\)

任意一個素數因子對答案貢獻的形式是相同的,單獨考慮一個 \(p_c\),則答案一定可以寫成 \(f(p_c) \cdot X\)

左邊:\(f(p_c) = a_c + b_c + 1\)

右邊:用一個數對錶示 \(p_c\)\(x\)\(y\) 中出現的冪次,形如 \((\alpha, 0)\)\((0, \beta)\) 的合法,則合法數對數即 \(f(p_c) = a_c + b_c + 1\)

左邊等於右邊。

利用上述公式推導:

\[\begin{aligned} \sum_{i = 1}^n\sum_{j = 1}^md(ij) &= \sum_{i = 1}^n\sum_{j = 1}^m\sum_{x \mid i}\sum_{y\mid j}[\gcd(x, y) = 1]\\ \\ &= \sum_{x = 1}^n\sum_{y = 1}^m\lfloor\dfrac{n}{x}\rfloor\lfloor\dfrac{m}{y}\rfloor \cdot [\gcd(x, y) = 1]\\ \\ &= \sum_{x = 1}^n\sum_{y = 1}^m\lfloor\dfrac{n}{x}\rfloor\lfloor\dfrac{m}{y}\rfloor \cdot \sum_{k \mid \gcd(x, y)}\mu(k)\\ \\ &= \sum_{k = 1}^n\mu(k)\sum_{i = 1}^{\lfloor\frac{n}{k}\rfloor}\lfloor\dfrac{n}{ik}\rfloor\cdot \sum_{j = 1}^{\lfloor\frac{m}{k}\rfloor}\lfloor\dfrac{m}{jk}\rfloor\\ \end{aligned} \]

\(f(n) = \sum_{i = 1}^n\lfloor\dfrac{n}{i}\rfloor\)

由於

\[\lfloor\dfrac{n}{ik}\rfloor = \lfloor\dfrac{\lfloor\dfrac{n}{k}\rfloor}{i}\rfloor \]

即求

\[\sum_{k = 1}^n\mu(k)\cdot f(\lfloor\frac{n}{k}\rfloor)\cdot f(\lfloor\frac{m}{k}\rfloor) \]

後面兩項可以 \(O(N\sqrt N)\) 預處理,也可以加個記憶化線上算。

P6222 「P6156 簡單題」加強版

設完全積性函式:\(g(n) = n^k\)

\[\begin{aligned} &=\sum_{i = 1}^n\sum_{j = 1}^ng(i + j)\gcd(i, j)\cdot \mu^2(\gcd(i, j))\\ \\ &= \sum_{d = 1}^nd\cdot g(d)\mu^2(d)\sum_{i = 1}^{n/d}\sum_{j = 1}^{n/d}[(i, j) =1]g(i + j)\\ \\ &= \sum_{d = 1}^nd\cdot g(d)\mu^2(d)\sum_{x = 1}^{n/d}\mu(x)g(x)\sum_{i = 1}^{n/d/x}\sum_{j = 1}^{n/d/x}g(i + j)\\ \end{aligned} \]

\(S(n) = \sum\limits_{i = 1}^n\sum\limits_{j = 1}^ng(i + j)\),列舉 \(T = xd\)

\[\begin{aligned} &= \sum_{d = 1}^nd\cdot g(d)\mu^2(d)\sum_{x = 1}^{n/d}\mu(x)g(x)S(n/T)\\ \\ &= \sum_{T = 1}^nS(n/T)\sum_{d \mid T}^nd\cdot g(d)\mu^2(d)\mu(\dfrac{T}{d})g(\dfrac{T}{d})\\ \\ &= \sum_{T = 1}^n S(n/T)\cdot g(T)\sum_{d \mid T}^nd\cdot \mu^2(d)\mu(\dfrac{T}{d})\\ \end{aligned} \]

\(F(n) = \sum_{d \mid n}d\cdot \mu^2(d)\mu(\dfrac{n}{d})\) 一定是積性函式,滿足:

\[F(p^c) = \begin{cases} p - 1 & c = 1\\ \\ -p & c = 2\\ \\ 0& c \ge 3 \end{cases} \]

對於 \(S\),有遞推式:

\[\begin{aligned} S(n) &= S(n - 1) + \sum_{i = 1}^{n - 1}g(n + i) + \sum_{j = 1}^{n - 1}g(n + j) + g(2n)\\ \\ &= S(n - 1) + sum_g(2n) + sum_g(2n - 1) - 2\times g(n)\\ \end{aligned} \]

最後即求

\[\sum_{T = 1}^n g(T)F(T)\cdot S(n/T) \]

所有預處理皆可以 \(O(n)\) 做完,查詢 \(O(\sqrt n)\)

P5221 Product

\[\begin{aligned} \prod_{i = 1}^n\prod_{j = 1}^n \dfrac{ij}{\gcd(i, j)^2} = \prod_{i = 1}^n\prod_{j = 1}^n ij\times (\prod_{i = 1}^n\prod_{j = 1}^n \gcd(i, j))^{-2} \end{aligned} \]

前一部分:

\[\prod_{i = 1}^n\prod_{j = 1}^n ij = \prod_{i = 1}^ni^n n! = (n!)^{2n} \]

後一部分:

\[\begin{aligned} \prod_{i = 1}^n\prod_{j = 1}^n \gcd(i, j) &= \prod_{d = 1}^n d^{\large\sum_{i = 1}^n\sum_{j = 1}^n[\gcd(i,j) = d]}\\ \\ &= \prod_{d = 1}^n d^{\large\sum_{i = 1}^{n/d}\sum_{j = 1}^{n/d}[\gcd(i,j) = 1]}\\ \\ &= \prod_{d = 1}^n d^{\large 2 \cdot sum_{\varphi}(n/d) - 1}\\ \end{aligned} \]

\(\varphi\) 的字首和會爆 int,計算時模 MOD - 1

P3704 [SDOI2017] 數字表格

\(n < m\)

\[\begin{aligned} \prod_{i = 1}^n\prod_{j = 1}^mf_{\gcd(i, j)} &= \prod_{d = 1}^nf_d^{\sum_{i = 1}^{n/d}\sum_{j = 1}^{m/d}[\gcd(i, j) = 1]}\\ \\ &= \prod_{d = 1}^nf_d^{\sum_{k = 1}^{n/d}\mu(k)\lfloor\frac{n}{dk}\rfloor\lfloor\frac{m}{dk}\rfloor} \\ \\ &= \prod_{T = 1}^n\prod_{d \mid T}f_d^{\mu(T/d)\lfloor\frac{n}{dk}\rfloor\lfloor\frac{m}{dk}\rfloor} \\ \\ &= \prod_{T = 1}^n(\prod_{d \mid T}f_d^{\mu(T/d)})^{\lfloor\frac{n}{dk}\rfloor\lfloor\frac{m}{dk}\rfloor} \\ \end{aligned} \]

中間的東西暴力預處理,複雜度調和級數再帶個快速冪。

P4619 [SDOI2018] 舊試題

首先有結論

\[d(ijk) = \sum_{x \mid i}\sum_{y\mid j}\sum_{z\mid k}[\gcd(x, y) = 1][\gcd(x, z) = 1][\gcd(y, z) = 1] \]

證明過程與 P3327 [SDOI2015] 約數個數和 如出一轍。

Part1 反演

\[\begin{aligned} &= \sum_{i = 1}^A\sum_{j = 1}^B\sum_{k = 1}^C\sum_{x \mid i}\sum_{y\mid j}\sum_{z\mid k}[\gcd(x, y) = 1][\gcd(x, z) = 1][\gcd(y, z) = 1]\\ \\ &= \sum_{x = 1}^A\sum_{y = 1}^B\sum_{z = 1}^C[\gcd(x, y) = 1][\gcd(x, z) = 1][\gcd(y, z) = 1]\lfloor\dfrac{A}{x}\rfloor\lfloor\dfrac{B}{y}\rfloor\lfloor\dfrac{C}{z}\rfloor\\ \\ &= \sum_{x = 1}^A\sum_{y = 1}^B\sum_{z =1}^C\lfloor\dfrac{A}{x}\rfloor\lfloor\dfrac{B}{y}\rfloor\lfloor\dfrac{C}{z}\rfloor\sum_{u \mid \gcd(x, y)}\mu(u)\sum_{v \mid\gcd(x, z)}\mu(v)\sum_{w \mid \gcd(y,z)}\mu(w)\\ \\ &= \sum_{u = 1}^{\min(A, B)}\sum_{v = 1}^{\min(A, C)}\sum_{w = 1}^{\min(B, C)}\mu(u)\mu(v)\mu(w)\sum_{\operatorname{lcm}(u, v)\mid x}\lfloor\dfrac{A}{x}\rfloor\sum_{\operatorname{lcm}(u, w)\mid y}\lfloor\dfrac{B}{y}\rfloor\sum_{\operatorname{lcm}(v, w)\mid z}\lfloor\dfrac{C}{z}\rfloor\\ \end{aligned} \]

\(f_x(d) = \sum_{d \mid n}\dfrac{x}{n}\)

則上式分別寫成 \(f_A(\operatorname{lcm}(u, v)), \ f_B(\operatorname{lcm}(u, w)), f_C(\operatorname{lcm}(v, w))\),可以 \(O(n\ln n)\) 預處理。

至此,複雜度 \(O(n^3)\),與暴力無異。

Part2 最佳化

任意 \(\mu\) 不為 \(0\)

任意 \(f_x(d)\) 不為 \(0\),即 \(d \le x\)

如果能跳過不滿足上述條件的情況,複雜度會大幅下降。

建圖。

如果 \(u, v\) 滿足 \(\mu(u) \ne 0 \land \mu(v) \ne 0\)\(\operatorname{lcm}(u, v) \le \max(A, B,C)\),則 \(u, v\) 有可能對答案產生貢獻,連無向邊。

新圖中的一個三元環對應一對合法的 \((u, v, w)\)

滿足條件的邊數 \(m\) 很小。

借用 P1989 無向圖三元環計數 的思路可以 \(O(m\sqrt m)\) 內找到每個環。

對於每個環,依次統計 \(6\) 種排列順序對答案的貢獻。

當然,上述過程只適用於 \(u, v, w\) 兩兩不同的情況,對於兩個元素相同或全相同的情況拎出來列舉即可。

樸素的建圖是 \(O(n^3)\) 的。

列舉 \(g\),將滿足 \(\gcd(u, v) = g \land \mu(u) \ne 0 \land\mu(v) \ne 0 \land\operatorname{lcm}(u, v) < \max V\) 的點對連邊(無序)。

trick:統計 \((u, v, w)\) 貢獻時,把上界統一設成 \(\max V\) 即可,如果 \(u > \min(A, B)\),則 \(f_A([u, v]), \ f_B([u, w])\) 至少一項為 \(0\)

#include<bits/stdc++.h>
#define ll long long
#define pb emplace_back
using namespace std;

constexpr int N = 1e5, P = 1e9 + 7;

int p[N], v[N + 5], idx, mu[N + 5];

void init() {
	mu[1] = 1;
	for(int i = 2; i <= N; ++ i) {
		if(v[i] == 0) {
			p[++ idx] = i;
			mu[i] = -1;
		}
		for(int j = 1; j <= idx && p[j] <= N / i; ++ j) {
			v[i * p[j]] = 1;
			if(i % p[j] == 0) {
				mu[i * p[j]] = 0;
				break;
			}
			mu[i * p[j]] = -mu[i];
		}
	}
}

int A, B, C, MX, MI, d[N + 5];
ll fa[N + 5], fb[N + 5], fc[N + 5], st[N + 5];

struct Node {
	int u, v, w;
} e[N << 3];
vector<pair<int, int>> G[N + 5];

void solve() {
	cin >> A >> B >> C, MX = max({A, B, C}), MI = min({A, B, C});
	memset(fa + 1, 0, MX * 8 + 8), memset(fb + 1, 0, MX * 8 + 8);
	memset(fc + 1, 0, MX * 8 + 8);
	for(int i = 1; i <= A; ++ i) for(int j = i; j <= A; j += i) fa[i] += A / j;
	for(int i = 1; i <= B; ++ i) for(int j = i; j <= B; j += i) fb[i] += B / j;
	for(int i = 1; i <= C; ++ i) for(int j = i; j <= C; j += i) fc[i] += C / j;
	ll ans = 0;
	// u = v = w
	for(int i = 1; i <= MI; ++ i) {
		if(mu[i]) (ans += mu[i] /** mu[i] * mu[i]*/ * fa[i] * fb[i] % P * fc[i]) %= P;
	}
	// 建圖 + 有兩個點相同
	for(int i = 1; i <= MX; ++ i) G[i].clear(); memset(d + 1, 0, MX * 4 + 4), idx = 0;
	for(int g = 1; g <= MX; ++ g) {
		for(int i = 1; i <= MX / g; ++ i) if(mu[i * g]) {
			for(int j = i + 1; j <= MX / g / i; ++ j) if(mu[j * g] && __gcd(i, j) == 1) {
				int u = i * g, v = j * g, Lcm = i * j * g;
				ans += mu[u] * mu[u] * mu[v] * (fa[u] * fb[Lcm] * fc[Lcm] + fa[Lcm] * fb[u] * fc[Lcm] + fa[Lcm] * fb[Lcm] * fc[u]);
				ans += mu[v] * mu[v] * mu[u] * (fa[v] * fb[Lcm] * fc[Lcm] + fa[Lcm] * fb[v] * fc[Lcm] + fa[Lcm] * fb[Lcm] * fc[v]);
				e[++ idx] = {u, v, Lcm}, ++ d[u], ++ d[v];
			}
		}
	}
	for(int i = 1; i <= idx; ++ i) {
		auto [u, v, w] = e[i];
		if(d[u] > d[v] || (d[u] == d[v] && u > v)) G[u].pb(v, w);
		if(d[u] < d[v] || (d[u] == d[v] && u < v)) G[v].pb(u, w);
	}
	for(int u = 1; u <= MX; ++ u) {
		for(auto [v, lcm1] : G[u]) st[v] = lcm1;
		for(auto [v, lcm1] : G[u]) {
			for(auto [w, lcm2] : G[v]) if(st[w]) {
				int lcm3 = st[w], uvw = mu[u] * mu[v] * mu[w];
				ans += uvw * (fa[lcm1] * fb[lcm2] * fc[lcm3]
							+ fa[lcm1] * fb[lcm3] * fc[lcm2]
							+ fa[lcm2] * fb[lcm1] * fc[lcm3]
							+ fa[lcm2] * fb[lcm3] * fc[lcm1]
							+ fa[lcm3] * fb[lcm1] * fc[lcm2]
							+ fa[lcm3] * fb[lcm2] * fc[lcm1]);
			}
		}
		for(auto [v, lcm1] : G[u]) st[v] = 0;
	}
	cout << (ans % P + P) % P << '\n';
}


int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	init();
	
	int T;
	cin >> T;
	
	while(T --) {
		solve();
	}
	return 0;
}

P5518 [MtOI2019] 幽靈樂團 / 莫比烏斯反演基礎練習題

Type0

\[\begin{aligned} P_0(A, B, C) &= \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C \dfrac{\operatorname{lcm}(i, j)}{\gcd(i, k)}\\ \\ &= \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C \dfrac{ij}{\gcd(i, j)\gcd(i, k)}\\ \end{aligned} \]

第一部分:

\[\begin{aligned} \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C ij &= \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C i \cdot \prod_{j = 1}^B\prod_{i = 1}^A\prod_{k = 1}^C j\\ \\ &= (\prod_{i = 1}^{A}i)^{BC} \cdot (\prod_{j = 1}^{B}j)^{AC}\\ \\ &= (A!)^{BC}\cdot (B!)^{AC} \end{aligned} \]

預處理 \(1\)\(N\) 的階乘。

第二部分:

\[\begin{aligned} \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C \gcd(i, j)\gcd(i, k) &= [\prod_{i = 1}^A\prod_{j = 1}^B \gcd(i, j)]^C \cdot [\prod_{i = 1}^A\prod_{k = 1}^C \gcd(i, k)]^B\\ \\ &= \text{calc}_0(A, B)^C\cdot \text{calc}_0(A, C)^B \end{aligned} \]

其中

\[\begin{aligned} \text{calc}_0(n, m) &= \prod_{i = 1}^n\prod_{j = 1}^m \gcd(i, j)\\ \\ &= \prod_{d = 1}^{\min(n, m)}d^{\large\sum_{i = 1}^{n/d}\sum_{j = 1}^{m/d} [\gcd(i, j) = 1]}\\ \\ &= \prod_{d = 1}^{\min(n, m)}d^{\large\sum_{k = 1}^{\min(n, m) / d}\mu(k)\lfloor\frac{n}{dk}\rfloor\lfloor\frac{m}{dk}\rfloor}\\ \\ &= \prod_{T = 1}^{\min(n, m)}\prod_{d \mid T}d^{\large\mu(\frac{T}{d})\lfloor\frac{n}{T}\rfloor\lfloor\frac{m}{T}\rfloor}\\ \end{aligned} \]

\(F_0(T) = \prod_{d \mid T} d^{\mu(\frac{T}{d})}\)

\[\begin{aligned} \text{calc}_0(n, m)= \prod_{T = 1}^{\min(n, m)}F_0(T)^{\lfloor\frac{n}{T}\rfloor\lfloor\frac{m}{T}\rfloor}\\ \end{aligned} \]

\(O(n\log n)\) 預處理 \(F_0\) 字首積及字首積的逆元,\(O(\sqrt n \log n)\) 數論分塊。

Type1

\[\begin{aligned} P_1(A, B, C) = \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C [\dfrac{ij}{\gcd(i, j)\gcd(i, k)}]^{ijk}\\ \end{aligned} \]

第一部分:

\[\begin{aligned} \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C i^{ijk} &= \prod_{i = 1}^A\prod_{j = 1}^Bi^{ij(\sum_{k = 1}^Ck)}\\ \\ &= [\prod_{i = 1}^Ai^i]^{(\sum_{j = 1}^Bj)(\sum_{k = 1}^Ck)}\\ \end{aligned} \]

\(f(n) = \sum_{i = 1}^ni\)

\[\prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C {ij}^{ijk} =[\prod_{i = 1}^Ai^i]^{f(B)f(C)} \cdot [\prod_{i = 1}^Bi^i]^{f(A)f(C)} \]

預處理 \(i^i\) 的字首積。

第二部分:

\[\begin{aligned} \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C \gcd(i, j)^{ijk} &= \prod_{i = 1}^A\prod_{j = 1}^B[ \gcd(i, j)^{ij}]^{f(c)}\\ \\ &= \text{calc}_1(A, B)^{f(C)} \end{aligned} \]

其中

\[\begin{aligned} \text{calc}_1(n, m) &= \prod_{i = 1}^n\prod_{j = 1}^m \gcd(i, j)^{ij}\\ \\ &= \prod_{d = 1}^{\min(n, m)}d^{\large d^2\sum_{i = 1}^{n/d}\sum_{j = 1}^{m/d} [\gcd(i, j) = 1]ij}\\ \\ &= \prod_{d = 1}^{\min(n, m)}d^{\large d^2\sum_{k = 1}^{\min(n, m) / d}k^2\mu(k)f(\lfloor\frac{n}{dk}\rfloor)f(\lfloor\frac{m}{dk}\rfloor})\\ \\ &= \prod_{T = 1}^{\min(n, m)}\prod_{d \mid T}d^{\large\mu(\frac{T}{d})T^2f(\lfloor\frac{n}{T}\rfloor)f(\lfloor\frac{m}{T}\rfloor)}\\ \end{aligned} \]

\(F_1(T) = \prod_{d \mid T} d^{\mu(\frac{T}{d})T^2} = F_0(T)^T\)

\[\begin{aligned} \text{calc}_1(n, m)= \prod_{T = 1}^{\min(n, m)}F_1(T)^{f(\lfloor\frac{n}{T}\rfloor)f(\lfloor\frac{m}{T}\rfloor)}\\ \end{aligned} \]

Type2

\[\begin{aligned} P_2(A, B, C) = \prod_{i = 1}^A\prod_{j = 1}^B\prod_{k = 1}^C [\dfrac{\text{lcm}(i, j)}{\gcd(i, k)}]^{\gcd(i, j, k)}\\ \end{aligned} \]

兩邊取對。

\[\begin{aligned} \ln P_2(A, B, C) &= \sum_{i = 1}^A\sum_{j = 1}^B\sum_{k = 1}^C \gcd(i, j, k)\ln\dfrac{\text{lcm}(i, j)}{\gcd(i, k)}\\ \\ &= \sum_{i = 1}^A\sum_{j = 1}^B\sum_{k = 1}^C \sum_{d\mid \gcd(i, j, k)}\varphi(d)\ln\dfrac{\text{lcm}(i, j)}{\gcd(i, k)}\\ \\ &= \sum_{d = 1}^{\min(A, B, C)}\varphi(d)\sum_{i = 1}^{A/d}\sum_{j = 1}^{B/d}\sum_{k = 1}^{C/d} \ln\dfrac{\text{lcm}(id, jd)}{\gcd(id, kd)}\\ \end{aligned} \]

兩邊 \(\exp\)

\[\begin{aligned} P_2(A, B, C) &= \prod_{d = 1}^{\min(A, B, C)}[\prod_{i = 1}^{A/d}\prod_{j = 1}^{B/d}\prod_{k = 1}^{C/d} \dfrac{\text{lcm}(i, j)} {\gcd(i, k)}]^{\varphi(d)}\\ \\ &= \prod_{d = 1}^{\min(A, B, C)}P_0(\lfloor\frac{A}{d}\rfloor, \lfloor\frac{B}{d}\rfloor, \lfloor\frac{C}{d}\rfloor)^{\varphi(d)}\\ \end{aligned} \]

本題卡常,應當把能預處理的逆元都預處理了。

相關文章