算是反演的板子題了吧……spa
然而我剛學反演因此仍是寫一寫題解吧。it
咱們要求$\sum \limits _{x=1}^{N} \sum \limits _{y=1}^{M} \left [ gcd(x,y)\in prime \right ]$io
枚舉質數:$\sum \limits _{g\in prime} \sum \limits _{x=1}^{\left \lfloor \frac{N}{g} \right \rfloor} \sum \limits _{y=1}^{\left \lfloor \frac{M}{g} \right \rfloor} \left [ gcd(x,y)=1 \right ]$gc
反演得原式=$\sum \limits _{g\in prime} \sum \limits _{x=1}^{\left \lfloor \frac{N}{g} \right \rfloor} \sum \limits _{y=1}^{\left \lfloor \frac{M}{g} \right \rfloor} \sum \limits _{t \mid gcd(x,y)} u(t)$im
將最後一個求和提早得原式=$\sum \limits _{g\in prime} \sum \limits _{t=1}^{min\left ( \left \lfloor \frac{N}{g} \right \rfloor,\left \lfloor \frac{M}{g} \right \rfloor \right )} u(t) \sum \limits _{x=1}^{\left \lfloor \frac{N}{g*t} \right \rfloor} \sum \limits _{y=1}^{\left \lfloor \frac{M}{g*t} \right \rfloor} 1$co
我本身推到這裏就頹題解了枚舉
令T=g*t,得$\sum \limits _{T=1}^{min(n,m)} \left ( \left \lfloor \frac{N}{T} \right \rfloor \left \lfloor \frac{M}{T} \right \rfloor * \sum \limits _{t\mid T,t\in prime} u(\frac{T}{t})\right )$gcd
後面的部分能夠用一個相似埃篩的東西預處理,前面的對於每次詢問整除分塊就好了。