[[gcd(i,j)==d]Rightarrow[frac {gcd(i,j)}d==1]Rightarrowsumlimits_{k|frac {gcd(i,j)}d}mu(k)
]
接下来,多半会设(kd=T)
[egin{split}
sum_{i=1}^nsum_{j=1}^m[gcd(i,j)==x]=sum_{d=1}^{lfloorfrac nx
floor}mu(d)lfloorfrac n{xd}
floorlfloorfrac m{xd}
floor
end{split}
]
题目
[egin{split}
sum_{x=1}^nsum_{i=1}^nsum_{j=1}^m[gcd(i,j)==x]&=sum_{x=1}^nsum_{d=1}^{lfloorfrac nx
floor}mu(d)lfloorfrac n{xd}
floorlfloorfrac m{xd}
floor\
&=sum_{T=1}^nlfloorfrac nT
floorlfloorfrac mT
floorsum_{x|T}mu(frac Tx)
end{split}
]
其中,(x)为枚举你想要的(gcd),(sum_{x|T}mu(frac Tx))需要在线性筛中预处理。
题目
[egin{split}
sumlimits_{i=1}^nsumlimits_{j=1}^mh(gcd(i,j))&=sumlimits_{d=1}^nh(d)sumlimits_{i=1}^{lfloorfrac nd
floor}mu(i)lfloorfrac n{id}
floorlfloorfrac m{id}
floor\
&=sumlimits_{T=1}^nlfloorfrac nT
floorlfloorfrac mT
floorsumlimits_{d|T}mu(frac Td)h(d)
end{split}
]
其中(h(x))为可以(O(1))计算的,仅与(gcd)有关的函数,(sumlimits_{d|T}mu(frac Td)h(d))需要在线性筛中预处理。
题目
[egin{split}
ans&=prodlimits_{i=1}^nprodlimits_{j=1}^mh(gcd(i,j))\
&=prodlimits_{T=1}^n(prodlimits_{d|T}h(d)^{mu(frac Td)})^{lfloorfrac n{T}
floorlfloorfrac m{T}
floor}
end{split}
]
其中(h(x))为可以(O(1))计算的,仅与(gcd)有关的函数,(prodlimits_{d|T}h(d)^{mu(frac Td)})需要在线性筛中预处理。
题目
[egin{split}
ans & =sumlimits_{i=1}^nsumlimits_{j=1}^m ext {lcm}(i,j) \
&=sumlimits_{d=1}^n dcdot sumlimits_{i=1}^{lfloorfrac n d
floor}mu(i)cdot g(i)\
&=sumlimits_{T=1}^nsum(lfloorfrac nT
floor)cdot sum(lfloorfrac mT
floor)cdot Tsumlimits_{i|T}mu(i)cdot i\
end{split}
]
其中,$g(x)=xcdot xcdot frac{(1+lfloorfrac{n}{x} floor)cdot lfloorfrac{n}{x} floor}{2}cdot frac{(1+lfloorfrac{m}{x} floor)cdot lfloorfrac{m}{x} floor}{2} $
其中(sum(i)=frac{(1+i)cdot(i)}{2}),可以直接计算出;(sumlimits_{i|T}mu(i)cdot i)为积性函数,可以预处理出。
题目