看题解才会的(指把题解瞅了个遍),没脸发题解
简单性质
[large
egin{aligned}
&varphi(ij)=ijprod_{pmid ij}frac{p-1}{p}\
&varphi( ext{gcd}(i,j))= ext{gcd}(i,j)prod_{pmid i,pmid j}frac{p-1}{p}\
&varphi(ij) imesvarphi( ext{gcd}(i,j))\
&=ijprod_{pmid ij}frac{p-1}{p} imes ext{gcd}(i,j)prod_{pmid i,pmid j}frac{p-1}{p}\
&=iprod_{pmid i}frac{p-1}{p} imes jprod_{pmid j}frac{p-1}{p} imesgcd(i,j)\
&=varphi(i)varphi(j) ext{gcd}(i, j)\
end{aligned}
]
[large{varphi(ij)=frac{varphi(i)varphi(j) ext{gcd}(i,j)}{varphi( ext{gcd}(i,j))}}
]
简单推导
[large
egin{aligned}
&nle m\
&sum_{i=1}^nsum_{j=1}^mvarphi(ij)\
&=sum_{i=1}^nsum_{j=1}^mvarphi(i)varphi(j)frac{ ext{gcd}(i, j)}{varphi( ext{gcd}(i,j))}\
&=sum_{d=1}^nsum_{i=1}^nsum_{j=1}^mvarphi(i)varphi(j)frac{d}{varphi(d)}[ ext{gcd}(i,j)=d]\
&=sum_{d=1}^nsum_{i=1}^{lfloorfrac{n}{d}
floor}sum_{j=1}^{lfloorfrac{m}{d}
floor}varphi(id)varphi(jd)frac{d}{varphi(d)}[ ext{gcd}(i,j)=1]\
&=sum_{d=1}^nsum_{i=1}^{lfloorfrac{n}{d}
floor}sum_{j=1}^{lfloorfrac{m}{d}
floor}varphi(id)varphi(jd)frac{d}{varphi(d)}sum_{kmid i,kmid j}mu(k)\
&=sum_{d=1}^nfrac{d}{varphi(d)}sum_{k=1}^{lfloorfrac{n}{d}
floor}mu(k)sum_{i=1}^{lfloorfrac{n}{kd}
floor}sum_{j=1}^{lfloorfrac{m}{kd}
floor}varphi(ikd)varphi(jkd)
ightarrow t=kd\
&=sum_{t=1}^nsum_{kmid t}mu(k)frac{frac{t}{k}}{varphi(frac{t}{k})}sum_{i=1}^{lfloorfrac{n}{t}
floor}varphi(it)sum_{j=1}^{lfloorfrac{m}{t}
floor}varphi(jt)\
&=sum_{t=1}^nsum_{kmid t}mu(frac{t}{k})frac{k}{varphi(k)}sum_{i=1}^{lfloorfrac{n}{t}
floor}varphi(it)sum_{j=1}^{lfloorfrac{m}{t}
floor}varphi(jt)
end{aligned}
]
毒瘤分析
[large sum_{t=1}^nsum_{kmid t}mu(frac{t}{k})frac{k}{varphi(k)}sum_{i=1}^{lfloorfrac{n}{t}
floor}varphi(it)sum_{j=1}^{lfloorfrac{m}{t}
floor}varphi(jt)
]
这个臃肿的式子无法满足我们的要求,只好看看能否更进一步
[large ext{osu}(x)=sum_{kmid t}mu(frac{t}{k})frac{k}{varphi(k)}
]
这一段线筛预处理,( ext{O(1)}) 查询(注意里面的欧拉函数用逆元)
[large G(lfloorfrac{n}{t}
floor,t)=sum_{i=1}^{lfloorfrac{n}{t}
floor}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,lfloorfrac{n}{t}
floor,lfloorfrac{m}{t}
floor)=sum_{t=1}^nsum_{kmid t}mu(frac{t}{k})frac{k}{varphi(k)}sum_{i=1}^{lfloorfrac{n}{t}
floor}varphi(it)sum_{j=1}^{lfloorfrac{m}{t}
floor}varphi(jt)
}
]
[large
egin{aligned}
&S(x,y,z)=sum_{t=1}^xsum_{kmid 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)+ ext{osu}(x) imes G(y,x) imes G(z,x)
end{aligned}
]
发现各个函数单独看也不是很难?
分个块勉强可以忍一下。(代码迫于枚举顺序参数位置稍有变动)