[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$

 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 }
View Code

posted @ 2019-10-05 17:33  Al_Ca  阅读(136)  评论(11编辑  收藏  举报