题目大意:给定(n,m),求
[sumlimits_{x=1}^{n} sumlimits_{y=1}^{n} [gcd(x,y)==k] (k∈prime)
]
莫比乌斯反演一般套路:
设(f(d))为(gcd(x,y)==d)的个数,(F(d))为(gcd(x,y)==k(d|k))的个数
即:
[f(d)=sumlimits_{i=1}^{n} sumlimits_{j=1}^{m}[gcd(i,j)==d]
]
这一步转化可以参考上一道例题中对于(f(d))的处理
[F(n)=sumlimits_{n|d}f(d)=lfloorfrac{N}{n}
floor lfloorfrac{M}{n}
floor
]
根据第二形式的莫比乌斯反演定理:
[f(n)=sumlimits_{n|d}mu(lfloorfrac{d}{n}
floor)F(d)
]
先把这些式子列出来,然后化简原式
[ret=sumlimits_{p∈prime} sumlimits_{i=1}^{n} sumlimits_{j=1}^{m}[gcd(i,j)==p]
]
[ret=sumlimits_{p∈prime} f(p)
]
[ret=sumlimits_{p∈prime} sumlimits_{p|d}mu(lfloorfrac{d}{p}
floor)F(d)
]
然后枚举因子改为枚举倍数
[ret=sumlimits_{p∈prime} sumlimits_{d=1}^{min(lfloorfrac{n}{p}
floor,lfloorfrac{m}{p}
floor)}mu(d)F(dp)
]
将(F(n))代入
[ret=sumlimits_{p∈prime} sumlimits_{d=1}^{min(lfloorfrac{n}{p}
floor,lfloorfrac{m}{p}
floor)}mu(d)lfloorfrac{n}{dp}
floorlfloorfrac{m}{dp}
floor
]
有一种可以降低复杂度的方法:
设(T=dp)
[ret=sumlimits_{T=1}^{min(n,m)} sumlimits_{t|T,t∈prime}mu(lfloorfrac{T}{t}
floor) lfloorfrac{n}{T}
floorlfloorfrac{m}{T}
floor
]
改变一下顺序
[ret=sumlimits_{T=1}^{min(n,m)}lfloorfrac{n}{T}
floorlfloorfrac{m}{T}
floor(sumlimits_{t|T,t∈prime}mu(lfloorfrac{T}{t}
floor))
]
最后面这个(sum)可以用埃氏筛求出来
复杂度(O(nloglogn+Tsqrt{n}))