Luogu5518

太闲了,推柿子!

\(type=1\)

\[\prod_{i=1}^A\prod_{j=1}^B\prod_{k=1}^C\frac{\operatorname{lcm}\{i,j\}}{\gcd\{i,k\}} \\=\prod_{i=1}^A\prod_{j=1}^B\prod_{k=1}^C\frac{ij}{\gcd\{i,k\}\gcd\{i,j\}} \\=\frac{A!^{BC}B!^{AC}}{\prod_{i=1}^A\prod_{j=1}^B\prod_{k=1}^C\gcd\{i,k\}\gcd\{i,j\}} \\=\frac{A!^{BC}B!^{AC}}{(\prod_{i=1}^A\prod_{j=1}^C\gcd\{i,j\})^B(\prod_{i=1}^A\prod_{j=1}^B\gcd\{i,j\})^C} \]

\[\prod_{i=1}^n\prod_{j=1}^m\gcd\{i,j\}=\prod_{p\in P}p^{\sum_{t\ge1}\lfloor\frac n{p^t}\rfloor\lfloor\frac m{p^t}\rfloor} \]

其中 \(P\) 代表质数集。(Product 的经典技巧)


\(type=2\)

\[\prod_{i=1}^A\prod_{j=1}^B\prod_{k=1}^C(\frac{\operatorname{lcm}\{i,j\}}{\gcd\{i,k\}})^{ijk} \\=\prod_{i=1}^A\prod_{j=1}^B\prod_{k=1}^C\frac{(ij)^{ijk}}{(\gcd\{i,k\}\gcd\{i,j\})^{ijk}} \]

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

\[\prod_{i=1}^A\prod_{j=1}^B\prod_{k=1}^C(\gcd\{i,k\}\gcd\{i,j\})^{ijk} \\=(\prod_{i=1}^A\prod_{j=1}^C\gcd\{i,j\}^{ij})^{\frac{B(B+1)}2}(\prod_{i=1}^A\prod_{j=1}^B\gcd\{i,j\}^{ij})^{\frac{C(C+1)}2} \]

\[\prod_{i=1}^n\prod_{j=1}^m\gcd\{i,j\}^{ij} \\=\prod_{p\in P}p^{\sum_{t\ge1}\sum_{i=1}^n\sum_{j=1}^mij[p^t|i][p^t|j]} \\=\prod_{p\in P}p^{\sum_{t\ge1}p^{2t}\frac{\lfloor\frac n{p^t}\rfloor(\lfloor\frac n{p^t}\rfloor+1)}2\frac{\lfloor\frac m{p^t}\rfloor(\lfloor\frac m{p^t}\rfloor+1)}2} \]


\(type=3\)

刚刚两问一个莫反都木有……

这里我懒了,直接欧拉反演(

\[\prod_{i=1}^A\prod_{j=1}^B\prod_{k=1}^C(\frac{\operatorname{lcm}\{i,j\}}{\gcd\{i,k\}})^{\gcd\{i,j,k\}} \\=\prod_d(\prod_{i=1}^{\lfloor\frac Ad\rfloor}\prod_{j=1}^{\lfloor\frac Bd\rfloor}\prod_{k=1}^{\lfloor\frac Cd\rfloor}\frac{\operatorname{lcm}\{i,j\}}{\gcd\{i,k\}})^{\varphi(d)} \]

\[\prod_d(\lfloor\frac Ad\rfloor!^{\lfloor\frac Bd\rfloor\lfloor\frac Cd\rfloor}\lfloor\frac Bd\rfloor!^{\lfloor\frac Ad\rfloor\lfloor\frac Cd\rfloor})^{\varphi(d)} \]

直接数论分块即可。

\[\prod_d((\prod_{i=1}^{\lfloor\frac Ad\rfloor}\prod_{j=1}^{\lfloor\frac Cd\rfloor}\gcd\{i,j\})^{\lfloor\frac Bd\rfloor}(\prod_{i=1}^{\lfloor\frac Ad\rfloor}\prod_{j=1}^{\lfloor\frac Bd\rfloor}\gcd\{i,j\})^{\lfloor\frac Cd\rfloor})^{\varphi(d)} \]

\[\prod_d(\prod_{i=1}^{\lfloor\frac Ad\rfloor}\prod_{j=1}^{\lfloor\frac Bd\rfloor}\gcd\{i,j\})^{\lfloor\frac Cd\rfloor\varphi(d)} \\=\prod_d(\prod_{p\in P}p^{\sum_{t\ge1}\lfloor\frac A{dp^t}\rfloor\lfloor\frac B{dp^t}\rfloor})^{\lfloor\frac Cd\rfloor\varphi(d)} \\=\prod_{p\in P}p^{\sum_{t\ge1}\sum_d\lfloor\frac A{dp^t}\rfloor\lfloor\frac B{dp^t}\rfloor\lfloor\frac Cd\rfloor\varphi(d)} \]

用数论分块暴力计算这个东西的复杂度依赖于和式

\[\sum_{p\in P}\sum_{t\ge1}\sqrt{\lfloor\frac n{p^t}\rfloor} \]

的量级。

\[\sum_{p\in P}\sum_{t\ge1}\sqrt{\lfloor\frac n{p^t}\rfloor} \\=O(\sum_{p\in P,p\le n}\sum_{t\ge1}\sqrt{\frac n{p^t}}) \\=O(\sum_{p\in P,p\le n}\sqrt{\frac np}) \\=O(\sum_{p\le n}\sqrt{\frac np}) \\=O(n) \]

因此暴力计算和式的复杂度是 \(O(n)\) 的。

再取 \(O(\frac n{\log n})\) 次快速幂,复杂度 \(O(n)\)

posted @ 2022-11-04 07:33  myee  阅读(31)  评论(1编辑  收藏  举报