[sum_{T=1}^{max(n,m,p)}left(nlfloorfrac{m}{T}
floorlfloorfrac{p}{T}
floor+lfloorfrac{n}{T}
floor mlfloorfrac{p}{T}
floor+lfloorfrac{n}{T}
floorlfloorfrac{m}{T}
floor p
ight)sum_{d|T}d^2mu(frac Td)
]
[egin{aligned}
Res=&sum_{i=1}^nsum_{j=1}^mvarphi(ij)\
=&sum_{i=1}^nsum_{j=1}^mfrac{varphi(i)varphi(j)gcd(i,j)}{varphi(gcd(i,j))}\
=&sum_{d=1}^nfrac{d}{varphi(d)}sum_{i=1}^nvarphi(i)sum_{j=1}^mvarphi(j)[gcd(i,j)=d]\
=&sum_{d=1}^nfrac{d}{varphi(d)}sum_{i=1}^{lfloorfrac{n}{d}
floor}varphi(id)sum_{j=1}^{lfloorfrac{m}{d}
floor}varphi(jd)[gcd(i,j)=1]\
=&sum_{d=1}^nfrac{d}{varphi(d)}sum_{i=1}^{lfloorfrac{n}{d}
floor}varphi(id)sum_{j=1}^{lfloorfrac{m}{d}
floor}varphi(jd)sum_{k|gcd(i,j)}mu(k)\
=&sum_{d=1}^nfrac{d}{varphi(d)}sum_{k=1}^{lfloorfrac{n}{d}
floor}mu(k)sum_{i=1}^{lfloorfrac{n}{dk}
floor}varphi(idk)sum_{j=1}^{lfloorfrac{m}{dk}
floor}varphi(jdk)\
=&sum_{T=1}^nsum_{d|T}frac{d}{varphi(d)}muleft(frac{T}{d}
ight)sum_{i=1}^{lfloorfrac{n}{T}
floor}varphi(iT)sum_{j=1}^{lfloorfrac{m}{T}
floor}varphi(jT)\
end{aligned}\
F(n)=sum_{d|n}frac{d}{varphi(d)}muleft(frac{n}{d}
ight)\
G(m,n)=sum_{i=1}^{n}varphi(im)=G(m,n-1)+varphi(nm)\
S(x,y,n)=sum_{T=1}^nsum_{d|T}frac{d}{varphi(d)}muleft(frac{T}{d}
ight)sum_{i=1}^{x}varphi(iT)sum_{j=1}^{y}varphi(jT)\
=S(x,y,n-1)+F(n)G(n,x)G(n,y)\
]
预处理全部 (F,G),一部分 (S),剩下靠分块。
[egin{aligned}
&sum_{i=1}^nsum_{j=1}^ni^pj^pgcd(i,j)\
=&sum_{d=1}^ndsum_{i=1}^ni^psum_{j=1}^nj^p[gcd(i,j)=d]\
=&sum_{d=1}^ndsum_{i=1}^{lfloorfrac nd
floor}(id)^psum_{j=1}^{lfloorfrac nd
floor}(jd)^p[gcd(i,j)=1]\
=&sum_{d=1}^nd^{2p+1}sum_{i=1}^{lfloorfrac nd
floor}i^psum_{j=1}^{lfloorfrac nd
floor}j^psum_{k|gcd(i,j)}mu(k)\
=&sum_{d=1}^nd^{2p+1}sum_{k=1}^{lfloorfrac nd
floor}mu(k)sum_{i=1}^{lfloorfrac n{dk}
floor}(ik)^psum_{j=1}^{lfloorfrac n{dk}
floor}(jk)^p\
=&sum_{d=1}^nd^{2p+1}sum_{k=1}^{lfloorfrac nd
floor}mu(k)k^{2p}sum_{i=1}^{lfloorfrac n{dk}
floor}i^psum_{j=1}^{lfloorfrac n{dk}
floor}j^p\
end{aligned}
]