题目
看题解才会的(指把题解瞅了个遍),没脸发题解
简单性质
\[\large
\begin{aligned}
&\varphi(ij)=ij\prod_{p\mid ij}\frac{p-1}{p}\\
&\varphi(\text{gcd}(i,j))=\text{gcd}(i,j)\prod_{p\mid i,p\mid j}\frac{p-1}{p}\\
&\varphi(ij)\times\varphi(\text{gcd}(i,j))\\
&=ij\prod_{p\mid ij}\frac{p-1}{p}\times\text{gcd}(i,j)\prod_{p\mid i,p\mid j}\frac{p-1}{p}\\
&=i\prod_{p\mid i}\frac{p-1}{p}\times j\prod_{p\mid j}\frac{p-1}{p}\\
&=\varphi(i)\varphi(j)\text{gcd}(i, j)\\
\end{aligned}
\]
\[\large{\varphi(ij)=\frac{\varphi(i)\varphi(j)\text{gcd}(i,j)}{\varphi(\text{gcd}(i,j))}}
\]
简单推导
\[\large
\begin{aligned}
&n\le m\\
&\sum_{i=1}^n\sum_{j=1}^m\varphi(ij)\\
&=\sum_{i=1}^n\sum_{j=1}^m\varphi(i)\varphi(j)\frac{\text{gcd}(i, j)}{\varphi(\text{gcd}(i,j))}\\
&=\sum_{d=1}^n\sum_{i=1}^n\sum_{j=1}^m\varphi(i)\varphi(j)\frac{d}{\varphi(d)}[\text{gcd}(i,j)=d]\\
&=\sum_{d=1}^n\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{d}\rfloor}\varphi(id)\varphi(jd)\frac{d}{\varphi(d)}[\text{gcd}(i,j)=1]\\
&=\sum_{d=1}^n\sum_{i=1}^{\lfloor\frac{n}{d}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{d}\rfloor}\varphi(id)\varphi(jd)\frac{d}{\varphi(d)}\sum_{k\mid i,k\mid j}\mu(k)\\
&=\sum_{d=1}^n\frac{d}{\varphi(d)}\sum_{k=1}^{\lfloor\frac{n}{d}\rfloor}\mu(k)\sum_{i=1}^{\lfloor\frac{n}{kd}\rfloor}\sum_{j=1}^{\lfloor\frac{m}{kd}\rfloor}\varphi(ikd)\varphi(jkd)\rightarrow t=kd\\
&=\sum_{t=1}^n\sum_{k\mid t}\mu(k)\frac{\frac{t}{k}}{\varphi(\frac{t}{k})}\sum_{i=1}^{\lfloor\frac{n}{t}\rfloor}\varphi(it)\sum_{j=1}^{\lfloor\frac{m}{t}\rfloor}\varphi(jt)\\
&=\sum_{t=1}^n\sum_{k\mid t}\mu(\frac{t}{k})\frac{k}{\varphi(k)}\sum_{i=1}^{\lfloor\frac{n}{t}\rfloor}\varphi(it)\sum_{j=1}^{\lfloor\frac{m}{t}\rfloor}\varphi(jt)
\end{aligned}
\]
毒瘤分析
\[\large \sum_{t=1}^n\sum_{k\mid t}\mu(\frac{t}{k})\frac{k}{\varphi(k)}\sum_{i=1}^{\lfloor\frac{n}{t}\rfloor}\varphi(it)\sum_{j=1}^{\lfloor\frac{m}{t}\rfloor}\varphi(jt)
\]
这个臃肿的式子无法满足我们的要求,只好看看能否更进一步
\[\large\text{osu}(x)=\sum_{k\mid t}\mu(\frac{t}{k})\frac{k}{\varphi(k)}
\]
这一段线筛预处理,\(\text{O(1)}\) 查询(注意里面的欧拉函数用逆元)
\[\large G(\lfloor\frac{n}{t}\rfloor,t)=\sum_{i=1}^{\lfloor\frac{n}{t}\rfloor}\varphi(it)
\]
明眼人都能看出参数来 =_=
\[\large {
G(x,y)=\sum_{i=1}^{x}\varphi(iy)\\
G(x,y)=\sum_{i=1}^{x-1}\varphi(iy)+\varphi(xy)=G(x-1,y)+\varphi(xy)\\
}
\]
然后拿着最后的一溜串结果搞事情~
\[\large{
S(n,\lfloor\frac{n}{t}\rfloor,\lfloor\frac{m}{t}\rfloor)=\sum_{t=1}^n\sum_{k\mid t}\mu(\frac{t}{k})\frac{k}{\varphi(k)}\sum_{i=1}^{\lfloor\frac{n}{t}\rfloor}\varphi(it)\sum_{j=1}^{\lfloor\frac{m}{t}\rfloor}\varphi(jt)
}
\]
\[\large
\begin{aligned}
&S(x,y,z)=\sum_{t=1}^x\sum_{k\mid t}\mu(\frac{t}{k})\frac{k}{\varphi(k)}\sum_{i=1}^{y}\varphi(it)\sum_{j=1}^{z}\varphi(jt)\\
&S(x,y,z)=S(x-1,y,z)+\text{osu}(x)\times G(y,x)\times G(z,x)
\end{aligned}
\]
发现各个函数单独看也不是很难?
分个块勉强可以忍一下。(代码迫于枚举顺序参数位置稍有变动)