「luogu4313」JZPTAB

 

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 #define R register
 4 using namespace std;
 5 const int N=10000010,mod=100000009;
 6 int n,m,p[N],tot;
 7 ll f[N];
 8 bool isp[N];
 9 int read(){
10     int x=0;char c=0;
11     while(c<'0'||c>'9') c=getchar();
12     while(c>='0'&&c<='9') x=(x<<3)+(x<<1)+c-48,c=getchar();
13     return x;
14 }
15 void getf(int lim){
16     f[1]=1;
17     for(R int i=2;i<=lim;i++){
18         if(!isp[i]) p[++tot]=i,f[i]=(1LL*(1-i)*i%mod+mod)%mod;
19         for(R int j=1;j<=tot&&1LL*p[j]*i<=lim;j++){
20             isp[i*p[j]]=1;
21             if(i%p[j]){f[i*p[j]]=f[i]*f[p[j]]%mod;}
22             else{
23                 f[i*p[j]]=f[i]*p[j]%mod;
24                 break;
25             }
26         }
27     }
28     for(int i=2;i<=lim;i++) f[i]=(f[i]+f[i-1])%mod;
29     return;
30 }
31 void solve(){
32     n=read(),m=read();
33     if(n>m) swap(n,m);
34     R int l=1,r;
35     ll ans=0;
36     while(l<=n){
37         r=min(n/(n/l),m/(m/l));
38         ll temp=(1LL*(n/l+1)*(n/l)/2%mod)*(1LL*(m/l+1)*(m/l)/2%mod)%mod;
39         ans=((ans+temp*(f[r]-f[l-1]))%mod+mod)%mod;
40         l=r+1;
41     }
42     printf("%lld\n",ans);
43     return;
44 }
45 int main(){
46     getf(10000000);
47     int T;
48     T=read();
49     while(T--) solve();
50     return 0;
51 }

 

posted @ 2018-03-15 09:27  Cupcake  阅读(97)  评论(0编辑  收藏  举报