[bzoj2693]jzptab
又没推出来……
不过通过这道题还是学到好多东西呢,比如积性函数,线筛什么的。
$\sum \limits _{i=1}^{n} \sum \limits _{j=1}^{m} lcm(i,j)$
=$\sum \limits _{d=1}^{min(n,m)} \sum \limits _{i=1}^{\left \lfloor \frac{n}{d} \right \rfloor} \sum \limits _{j=1}^{\left \lfloor \frac{m}{d} \right \rfloor} i*j*d \left [ gcd(i,j)=1 \right ]$
=$\sum \limits _{d=1}^{min(n,m)} \sum \limits _{i=1}^{\left \lfloor \frac{n}{d} \right \rfloor} \sum \limits _{j=1}^{\left \lfloor \frac{m}{d} \right \rfloor} \left ( i*j*d *\sum \limits _{t\mid gcd(i,j)}u(t) \right )$
=$\sum \limits _{d=1}^{min(n,m)} d* \sum \limits _{i=1}^{\left \lfloor \frac{n}{d} \right \rfloor} \sum \limits _{j=1}^{\left \lfloor \frac{m}{d} \right \rfloor} \left ( i*j *\sum \limits _{t\mid gcd(i,j)}u(t) \right )$
=$\sum \limits _{d=1}^{min(n,m)} d* \sum \limits _{t=1}^{min\left ( \left \lfloor \frac{n}{d} \right \rfloor \left \lfloor \frac{m}{d} \right \rfloor\right )} u(t) * t^2 *\sum \limits _{i=1}^{\left \lfloor \frac{n}{d*t} \right \rfloor} \sum \limits _{j=1}^{\left \lfloor \frac{m}{d*t} \right \rfloor} i*j$
自己推到这就又不会了……
主要是没想到这玩意:$\sum \limits _{i} \sum \limits _{j} \left ( i*j \right )= \sum \limits _{i} \left ( i*\sum \limits _{j} j\right ) = \left ( \sum \limits _{i}i \right )*\left ( \sum \limits _{j}j \right )$
于是原式=$\sum \limits _{d=1}^{min(n,m)} \sum \limits _{t=1}^{min\left ( \left \lfloor \frac{n}{d} \right \rfloor ,\left \lfloor \frac{m}{d} \right \rfloor \right )} u(t) * t^2 *\left ( \sum \limits _{i=1}^{\left \lfloor \frac{n}{d*t} \right \rfloor}i \right ) * \left ( \sum \limits _{j=1}^{\left \lfloor \frac{m}{d*t} \right \rfloor}j \right )$
后面是一个等差数列,原式=$\sum \limits _{d=1}^{min(n,m)} d* \left ( \sum \limits _{t=1}^{min\left ( \left \lfloor \frac{n}{d} \right \rfloor \left \lfloor \frac{m}{d} \right \rfloor \right )} u(t)*t^2 *\frac{\left \lfloor \frac{n}{d*t} \right \rfloor *\left ( \left \lfloor \frac{n}{d*t} \right \rfloor +1 \right ) * \left \lfloor \frac{m}{d*t} \right \rfloor \left ( \left \lfloor \frac{m}{d*t} \right \rfloor +1 \right )}{4} \right )$
令T=d*t,原式=$\sum \limits _{T=1}^{min(n,m)} \frac{\left \lfloor \frac{n}{T} \right \rfloor * \left ( \left \lfloor \frac{m}{T} \right \rfloor +1 \right ) * \left \lfloor \frac{m}{T} \right \rfloor * \left ( \left \lfloor \frac{m}{T} \right \rfloor +1 \right )}{4} * T*\sum \limits _{t\mid T}u(t)*t $
到这里式子就推完了(稍恶心),之后设$f(n)=n*\sum \limits _{t\mid n} u(t)*t$,通过一些我看不懂的证明可以发现它是积性函数,于是我们可以用线筛搞出来它,前面的部分整除分块就可以了。
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #define int LL 5 #define LL long long 6 using namespace std; 7 const int mod=100000009; 8 bool noprime[12000000]; 9 int prime[12000000],cnt; 10 int low[12000000],f[12000000],mu[12000000]; 11 void shai(int n) 12 { 13 f[1]=mu[1]=1; 14 for(int i=2;i<=n;i++) 15 { 16 if(!noprime[i]) prime[++cnt]=i,mu[i]=-1,f[i]=-i+1+mod; 17 for(int j=1;j<=cnt&&prime[j]*i<=n;j++) 18 { 19 noprime[prime[j]*i]=1; 20 if(i%prime[j]==0){f[i*prime[j]]=f[i];break;} 21 f[i*prime[j]]=(f[i]*f[prime[j]])%mod;mu[i*prime[j]]=-mu[i]; 22 } 23 } 24 for(int i=1;i<=n;i++)f[i]=f[i]*i%mod; 25 for(int i=1;i<=n;i++)f[i]=(f[i]+f[i-1])%mod; 26 } 27 LL get(LL x){return (x*(x+1)/2)%mod;} 28 int T,n,m; 29 signed main() 30 { 31 shai(12000000); 32 cin>>T; 33 while(T--) 34 { 35 cin>>n>>m;if(n>m)swap(n,m); 36 LL ans=0; 37 for(int l=1,r;l<=n;l=r+1) 38 { 39 r=min(n/(n/l),m/(m/l)); 40 ans=(ans+get(n/l)*get(m/l)%mod*((f[r]-f[l-1]+mod)%mod)%mod)%mod; 41 } 42 printf("%lld\n",(ans%mod+mod)%mod); 43 } 44 }