bzoj2693 莫比乌斯反演
Description
Hint
T <= 10000
N, M<=10000000
https://wenku.baidu.com/view/fbec9c63ba1aa8114431d9ac.html
popoqqq的论文
1 #pragma GCC optimize(2) 2 #pragma G++ optimzie(2) 3 #include<cstring> 4 #include<cmath> 5 #include<iostream> 6 #include<cstdio> 7 #include<algorithm> 8 9 #define mod 100000009 10 #define N 10000007 11 #define ll long long 12 using namespace std; 13 inline int read() 14 { 15 int x=0,f=1;char ch=getchar(); 16 while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();} 17 while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();} 18 return x*f; 19 } 20 21 int T,n,m; 22 int tot; 23 bool flag[N]; 24 ll h[N],pri[N]; 25 26 void init() 27 { 28 h[1]=1; 29 for (int i=2;i<N;i++) 30 { 31 if(!flag[i]) 32 { 33 pri[++tot]=i; 34 h[i]=(i-(ll)i*i)%mod; 35 } 36 for (int j=1;j<=tot&&pri[j]*i<N;j++) 37 { 38 flag[pri[j]*i]=true; 39 if(i%pri[j]==0) 40 { 41 h[pri[j]*i]=(pri[j]*h[i])%mod; 42 break; 43 } 44 else h[pri[j]*i]=(h[pri[j]]*h[i])%mod; 45 } 46 } 47 for (int i=1;i<N;i++) 48 (h[i]+=h[i-1])%=mod; 49 } 50 inline ll sum(ll x,ll y) 51 { 52 x%=mod,y%=mod; 53 x*=(x+1),(x=x/2)%=mod; 54 y*=(y+1),(y=y/2)%=mod; 55 return x*y%mod; 56 } 57 ll query(int n,int m) 58 { 59 ll res=0; 60 if(n>m)swap(n,m); 61 for (int i=1,last;i<=n;i=last+1) 62 { 63 last=min(n/(n/i),m/(m/i)); 64 res+=sum(n/i,m/i)*(h[last]-h[i-1])%mod; 65 res%=mod; 66 } 67 return (res%mod+mod)%mod; 68 } 69 int main() 70 { 71 T=read(),init(); 72 while(T--) 73 { 74 n=read(),m=read(); 75 printf("%lld\n",query(n,m)); 76 } 77 }