bzoj2693 jzptab
题意
承接这题:
\(\sum\limits_{d=1}^{n}d*\sum\limits_{x=1}^{\frac{n}{d}}x^2*\mu(x)(\sum\limits_{i=1}^{\frac{n}{d*x}}i)(\sum\limits_{j=1}^{\frac{m}{d*x}}j)\)
设\(T=d*x\),\(sum(x)=\sum\limits_{i=1}^{n}i\):
\(\sum\limits_{T=1}^{n}sum(\frac{n}{T})*sum(\frac{m}{T})\sum\limits_{d|T}d*\frac{T^2}{d^2}\mu(\frac{T}{d})\)
\(\sum\limits_{T=1}^{n}sum(\frac{n}{T})*sum(\frac{m}{T})T*\sum\limits_{d|T}\frac{T}{d}\mu(\frac{T}{d})\)
\(\sum\limits_{T=1}^{n}sum(\frac{n}{T})*sum(\frac{m}{T})T*\sum\limits_{d|T}d\mu(d)\)
考虑如何求\(f(T)=\sum\limits_{d|T}d\mu(d)\):
这是个积性函数:
证明:
显然有\(f(p^k)=1-p\)。
设\(n=p_1^{c_1}*p_2^{c_2}*...*p_k^{c_k}\)。
考虑求出了\(f(p_1^{c_1}*p_2^{c_2}*...*p_{k-1}^{c_{k-1}})\),现在加入\(p_k^{c_k}\),考虑加上\(2\)个以上\(p_k\)的约数的\(\mu()\)为\(0\),不考虑,加上\(0\)个的约数和原来相同,加上\(1\)个的约数\(\mu\)会变号,因此:
\(f(n)=f(p_1^{c_1}*p_2^{c_2}*...*p_{k-1}^{c_{k-1}})*1-f(p_1^{c_1}*p_2^{c_2}*...*p_{k-1}^{c_{k-1}})*p=f(p_1^{c_1}*p_2^{c_2}*...*p_{k-1}^{c_{k-1}})*f(p_k^{c_k})\)
于是可以线性筛求出,询问只需除法分块即可。
注意模数是\(10^8+9\)!!!!!!!!!!!!!!
code:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=10000010;
const ll mod=1e8+9;
int T,n,m;
ll f[maxn],sum[maxn],s[maxn];
bool vis[maxn];
vector<int>prime;
inline void pre_work(int n)
{
vis[1]=1;f[1]=1;
for(int i=2;i<=n;i++)
{
if(!vis[i])prime.push_back(i),f[i]=(mod+1-i)%mod;
for(unsigned int j=0;j<prime.size()&&i*prime[j]<=n;j++)
{
vis[i*prime[j]]=1;
if(i%prime[j]==0){f[i*prime[j]]=f[i];break;}
f[i*prime[j]]=f[i]*f[prime[j]]%mod;
}
}
for(int i=1;i<=n;i++)sum[i]=(sum[i-1]+1ll*i*f[i]%mod)%mod;
for(int i=1;i<=n;i++)s[i]=(s[i-1]+i)%mod;
}
inline ll solve(int n,int m)
{
ll res=0;
if(n>m)swap(n,m);
for(int l=1,r;l<=n;l=r+1)
{
r=min(n/(n/l),m/(m/l));
res=(res+s[n/l]*s[m/l]%mod*((sum[r]-sum[l-1])%mod+mod)%mod)%mod;
}
return res;
}
int main()
{
pre_work(10000000);
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
printf("%lld\n",solve(n,m));
}
return 0;
}