首页 > 其他分享 >P5518 [MtOI2019]幽灵乐团 / 莫比乌斯反演基础练习题

P5518 [MtOI2019]幽灵乐团 / 莫比乌斯反演基础练习题

时间:2023-06-09 13:34:10浏览次数:44  
标签:P5518 lfloor frac log sum rfloor MtOI2019 反演 prod

简要题意

计算

\[\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}\left(\frac{\text{lcm}(i,j)}{\gcd(i,k)}\right)^{f(type)} \]

其中:

\[\begin{aligned} f(0)&=1 \cr f(1)&=i \times j \times k \cr f(2)&=\gcd(i,j,k) \end{aligned}\]

\(T\) 组数据,每组数据给出 \(A,B,C\),输出在 \(\text{type}=0,1,2\) 的值,对预先给出的质数 \(p\) 取模。

思路

魔鬼乐团……没看 tj 切黑题系列。

type=0

\[\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}\left(\frac{\text{lcm}(i,j)}{\gcd(i,k)}\right) \]

原式取 \(\log\) 得:

\[\begin{aligned} &A\leq B\leq C\\ &\sum_{i=1}^{A}\sum_{j=1}^{B}\sum_{k=1}^{C}\log(\operatorname{lcm}(i,j))-\log(\gcd(i,k))\\ &=C\sum_{i=1}^{A}\sum_{j=1}^{B}\log(\operatorname{lcm}(i,j))-B\sum_{i=1}^{A}\sum_{k=1}^{C}\log(\gcd(i,k))\\ &=C\sum_{i=1}^{A}\sum_{j=1}^{B}\log(i)+\log(j)-\log(\gcd(i,j))-\\&\ B(\sum_{d=1}^{A}\lfloor\frac{A}{d}\rfloor\lfloor\frac{C}{d}\rfloor\sum_{k|d}\mu(\frac{d}{k})\log(k))\\ &=C\sum_{i=1}^{A}\sum_{j=1}^{B}\log(i)+C\sum_{i=1}^{B}\sum_{j=1}^{A}\log(i)-\\&C(\sum_{d=1}^{A}\lfloor\frac{A}{d}\rfloor\lfloor\frac{B}{d}\rfloor\sum_{k|d}\mu(\frac{d}{k})\log(k))-B(\sum_{d=1}^{A}\lfloor\frac{A}{d}\rfloor\lfloor\frac{C}{d}\rfloor\sum_{k|d}\mu(\frac{d}{k})\log(k))\\ &F(d)=\sum_{k|d}\mu(\frac{d}{k})\log(k))\\ &=BC\log(A!)+AC\log(B!)-C(\sum_{d=1}^{A}\lfloor\frac{A}{d}\rfloor\lfloor\frac{B}{d}\rfloor F(d))-B(\sum_{d=1}^{A}\lfloor\frac{A}{d}\rfloor\lfloor\frac{C}{d}\rfloor F(d)) \end{aligned} \]

现在的式子取 \(\exp\)

\[\begin{aligned} &f(d)=\exp(F)=\prod_{k|d}\mu(k)^{\frac{d}{k}}\\ &=(A!)^{BC}\cdot(B!)^{AC}\cdot\dfrac{1}{C(\prod_{d=1}^{A}f(d)^{\lfloor\frac{A}{d}\rfloor\lfloor\frac{B}{d}\rfloor})\cdot B(\prod_{d=1}^{A}f(d)^{\lfloor\frac{A}{d}\rfloor\lfloor\frac{C}{d}\rfloor}} \end{aligned} \]

type=1

\[\begin{aligned} &\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}\left(\frac{\text{lcm}(i,j)}{\gcd(i,k)}\right)^{ijk}\\ &F=\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}(ij)^{ijk},G(x,y)=\prod_{i=1}^{A}\prod_{j=1}^{x}\prod_{k=1}^{y}\gcd(i,j)^{ijk}\\ &=\frac{F}{G(B,C)G(C,B)} \end{aligned} \]

先推 \(F\):

\[\begin{aligned} &F=\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}(ij)^{ijk}\\ &=\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}i^{ijk}\cdot\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}j^{ijk}\\ &=\prod_{i=1}^{A}i^{\sum_{j=1}^{B}j\cdot\sum_{k=1}^{C}k}\cdot\prod_{i=1}^{B}i^{\sum_{j=1}^{A}j\cdot\sum_{k=1}^{C}k}\\ &W(x)=\sum_{i=1}^{x}i=\frac{x(x+1)}{2}\\ &=\prod_{i=1}^{A}i^{W(B)W(C)}\cdot\prod_{i=1}^{B}i^{W(A)W(C)}\\ &=(A!)^{W(B)W(C)}\cdot(B!)^{W(A)W(C)} \end{aligned} \]

然后是 \(G\),取 \(g=\log(G)\) 得:

\[\begin{aligned} &A\leq B\leq C\\ &g=\log(\prod_{i=1}^{A}\prod_{j=1}^{x}\prod_{k=1}^{y}\gcd(i,j)^{ijk})\\ &=\sum_{i=1}^{A}\sum_{j=1}^{x}\sum_{k=1}^{y}ijk\log(\gcd(i,j))\\ &=\sum_{k=1}^{y}k\sum_{i=1}^{A}\sum_{j=1}^{x}ij\log(\gcd(i,j))\\ &=W(y)\sum_{i=1}^{A}\sum_{j=1}^{x}ij\log(\gcd(i,j))\\ &=W(y)\sum_{p=1}^{A}\log(p)\sum_{i=1}^{A}\sum_{j=1}^{x}ij[\gcd(i,j)=p]\\ &=W(y)\sum_{p=1}^{A}\log(p)p^2\sum_{i=1}^{\lfloor\frac{A}{p}\rfloor}\sum_{j=1}^{\lfloor\frac{x}{p}\rfloor}ij[\gcd(i,j)=1]\\ &=W(y)\sum_{p=1}^{A}\log(p)p^2\sum_{i=1}^{\lfloor\frac{A}{p}\rfloor}\sum_{j=1}^{\lfloor\frac{x}{p}\rfloor}ij\sum_{d|i,d|j}\mu(d)\\ &=W(y)\sum_{p=1}^{A}\log(p)p^2\sum_{d=1}^{A}\mu(d)\sum_{i=1}^{\lfloor\frac{A}{dp}\rfloor}id\sum_{j=1}^{\lfloor\frac{x}{dp}\rfloor}jd\\ &=W(y)\sum_{p=1}^{A}\log(p)p^2\sum_{d=1}^{A}\mu(d)\sum_{i=1}^{\lfloor\frac{A}{dp}\rfloor}id\sum_{j=1}^{\lfloor\frac{x}{dp}\rfloor}jd\\ &=W(y)\sum_{p=1}^{A}\log(p)p^2\sum_{d=1}^{A}\mu(d)d^2W(\lfloor\frac{A}{dp}\rfloor)W(\lfloor\frac{x}{dp}\rfloor)\\ &=W(y)\sum_{T=1}^{A}W(\lfloor\frac{A}{T}\rfloor)W(\lfloor\frac{x}{T}\rfloor)\sum_{d|T}\mu(d)d^2\log(\frac{T}{d})(\frac{T}{d})^2\\ &=W(y)\sum_{T=1}^{A}T^2W(\lfloor\frac{A}{T}\rfloor)W(\lfloor\frac{x}{T}\rfloor)\sum_{d|T}\mu(d)\log(\frac{T}{d}) \end{aligned} \]

取 \(G=\exp(g)\) 得:

\[G(x,y)=(\prod_{T=1}^{A}(\prod_{d|T}(\frac{T}{d})^{\mu(d)})^{T^2W(\lfloor\frac{A}{T}\rfloor)W(\lfloor\frac{x}{T}\rfloor)})^{W(y)} \]

预处理 \(\prod_{d|T}(\frac{T}{d})^{\mu(d)})^{T^2}\) 即可。

type=2

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

取 \(\log\) 得:

\[\begin{aligned} &\log(\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}\left(\frac{\text{lcm}(i,j)}{\gcd(i,k)}\right)^{\gcd(i,j,k)})\\ &=\sum_{i=1}^{A}\sum_{j=1}^{B}\sum_{k=1}^{C}\log(\text{lcm}(i,j))\gcd(i,j,k)-\log(\text{gcd}(i,k))\gcd(i,j,k)\\ &=\sum_{i=1}^{A}\sum_{j=1}^{B}\sum_{k=1}^{C}\left(\sum_{d|i,d|j,d|k}\varphi(d)\right)(\log(\text{lcm}(i,j))-\log(\gcd(i,k)))\\ &=\sum_{d=1}^{A}\varphi(d)\sum_{i=1}^{A}\sum_{j=1}^{B}\sum_{k=1}^{C}[d|A][d|B][d|C]\log(\text{lcm}(i,j))-\log(\gcd(i,k))\\ &=\sum_{d=1}^{A}\varphi(d)\sum_{i=1}^{\lfloor\frac{A}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{B}{d}\rfloor}\sum_{k=1}^{\lfloor\frac{C}{d}\rfloor}\log(d\cdot\text{lcm}(i,j))-\log(d\cdot\gcd(i,k))\\ &=\sum_{d=1}^{A}\varphi(d)\sum_{i=1}^{\lfloor\frac{A}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{B}{d}\rfloor}\sum_{k=1}^{\lfloor\frac{C}{d}\rfloor}\log(\text{lcm}(i,j))-\log(\gcd(i,k))\\ \end{aligned} \]

取 \(\exp\) 得:

\[\prod_{d=1}^{A}\left(\prod_{i=1}^{\lfloor\frac{A}{d}\rfloor}\prod_{j=1}^{\lfloor\frac{B}{d}\rfloor}\prod_{k=1}^{\lfloor\frac{C}{d}\rfloor}\left(\frac{\text{lcm}(i,j)}{\gcd(i,k)}\right)\right)^{\varphi(d)} \]

里面就是 type=0。数论分块套数论分块,做完了。

标签:P5518,lfloor,frac,log,sum,rfloor,MtOI2019,反演,prod
From: https://www.cnblogs.com/zheyuanxie/p/p5518.html

相关文章

  • 算法学习笔记(24): 狄利克雷卷积和莫比乌斯反演
    狄利克雷卷积和莫比乌斯反演看了《组合数学》,再听了学长讲的……感觉三官被颠覆……目录狄利克雷卷积和莫比乌斯反演狄利克雷卷积特殊的函数函数之间的关系除数函数和幂函数欧拉函数和恒等函数卷积的逆元莫比乌斯函数与莫比乌斯反演求法数论分块(整除分块)莫比乌斯反演的经典结......
  • 莫比乌斯反演
    这里讲述几个莫比乌斯反演的套路技巧。我们从一道道例题讲起。\(\sum_{i=1}^{n}\sum_{j=1}^{n}[gcd(i,j)=1]=\sum_{i=1}^n\mu(i)\lfloor\frac{n}{i}\rfloor^2\)这就是一般公式\([gcd(i,j)=1]=\sum_{d|i,d|j}^n\mu(d)\)的衍生,不会做不了题。暴力算\(\gcd\)转换为枚举......
  • 二项式反演两题
    例题一[JSOI2011]分特产题目描述JYY带队参加了若干场\(\text{ACM/ICPC}\)比赛,带回了许多土特产,要分给实验室的同学们。JYY想知道,把这些特产分给\(n\)个同学,一共有多少种不同的分法?当然,JYY不希望任何一个同学因为没有拿到特产而感到失落,所以每个同学都必须至少分得一个......
  • 【反演】基于遗传算法实现均匀地层模型随钻电磁波测井反演附matlab代码
    ✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。......
  • 子集反演
    什么是子集反演?当然在此之前说明子集反演是什么:子集反演用于在恰好是某个子集和在这个子集中钦定/钦定这个子集之间转换。并且子集反演有两种形式。第一种:现在有一个集合\(A\),我们定义\(f(A)\)表示集合\(A\)的答案,\(g(A)\)表示\(A\)的所有子集的答案。如果有......
  • [MtOI2019]幽灵军团
    题意求下面表达式的值,\[\prod_{i=1}^{A}\prod_{j=1}^{B}\prod_{k=1}^{C}\left(\frac{lcm(i,j)}{gcd(i,k)}\right)^{f(type)}\pmod{p}\]其中,\(type=\{0,1,2\}\),\(f(type)\)满足:\[f(0)=1,\]\[f(1)=i\timesj\timesk,\]\[f(2)=gcd(i,j,k).\]其中,......
  • 莫比乌斯反演
    莫比乌斯反演的题主要是构造\(F(n)\)以及\(f(n)\)例题老地方......
  • 莫比乌斯反演与最大公约数
    在数论中,有很多题目都与莫比乌斯反演有关,最典型的就是最大公约数。比如你可以见到如下常见问题。(1)已知,求为质数的的对数,或者等于1的的对数。(2)已知和,求为质数的的对数,或者等于1的的对数。(3)已知,求的对数。(4)已知和,求的对数。上面的问题其实都可以用莫比乌斯反演来解,时间复杂度都还可以......
  • 浅谈反演
    浅谈反演二项式反演\(g_i=\sum\limits_{j=0}\binom{i}{j}f_j,f_i=\sum\limits_{j=0}(-1)^{i-j}\binom{i}{j}g_j\)还有一个的形式\(g_i=\sum\limits_{j=i}\binom{j}{i}f_j,f_i=\sum\limits_{j=i}(-1)^{i-j}\binom{j}{i}g_j\)这里只针对第一个形式,为了得到更普遍的反演,这里我......
  • 容斥与反演技巧(三)
    Min-Max容斥简单来说,由于\(\mathbbE[\max(x,y)]\neq\max(\mathbbE[x],\mathbbE[y])\),而如果计算\(\mathbbE[\min(x,y)]\)比计算\(\mathbbE[\max(x,y)]\)容易得多,我们就通常使用min-max容斥转为计算\(\mathbbE[\min(x,y)]\)。对于上面这种\(x,y\)的情况,实际上......