# BZOJ 2693 jzptab 【莫比乌斯反演】

T <= 10000
N, M<=10000000

## Solution

 1 #include<bits/stdc++.h>
2
3 #define mod 100000009
4 #define maxp 10000000
5 #define maxn 10000000+5
6 #define set(a,b) memset(a,(b),sizeof(a))
7 #define fr(i,a,b) for(ll i=(a),_end_=(b);i<=_end_;i++)
8 #define rf(i,b,a) for(ll i=(a),_end_=(b);i>=_end_;i--)
9 #define fe(i,a,b) for(int i=first[(b)],_end_=(a);i!=_end_;i=s[i].next)
10 #define fec(i,a,b) for(int &i=cur[(b)],_end_=(a);i!=_end_;i=s[i].next)
11
12 using namespace std;
13
14 typedef long long ll;
15
16 ll f[maxn],h[maxn];
17 ll ans;
18 int prime[maxn],pri[maxn],tot=0;
19 int n,m,T;
20
22 {
23 #ifndef ONLINE_JUDGE
24   freopen("2693.in","r",stdin);
25   freopen("2693.out","w",stdout);
26 #endif
27   //cin >> T ;
28   scanf("%d",&T);
29 }
30
31 void write()
32 {}
33
34 void print()
35 {
36   //cout << ans << endl ;
37   printf("%lld\n",ans);
38 }
39
40 void get()
41 {
42   h[1]=1;
43   fr(i,2,maxp){
44     if( !prime[i] ) pri[++tot]=i,h[i]=(i-i*i%mod)%mod;
45     int j=1;
46     while( j<=tot && pri[j]*i<=maxp ){
47       prime[ pri[j]*i ]=1;
48       if( i%pri[j]==0 ){
49     h[pri[j]*i]=pri[j]*h[i]%mod;
50     break;
51       }
52       h[pri[j]*i]=h[pri[j]]*h[i]%mod;
53       j++;
54     }
55   }
56   fr(i,1,maxp)
57     f[i]=(f[i-1]+h[i])%mod;
58 }
59
60 ll Sum(ll x,ll y)
61 {
62   return ((x+1)*x/2%mod)*((y+1)*y/2%mod)%mod;
63 }
64
65
66 ll calc(ll x,ll y)
67 {
68   if( x>y ) swap(x,y);
69   ll res=0,i=1,pos;
70   while( i<=x ){
71     pos=min(x/(x/i),y/(y/i));
72     res=(res+Sum(x/i,y/i)*(f[pos]-f[i-1])%mod)%mod;
73     i=pos+1;
74   }
75   return (res+mod)%mod;
76 }
77
78 void work()
79 {
80   get();
81   while( T-- ){
82     //cin >> n >> m ;
83     scanf("%d%d",&n,&m);
84     ans=calc(n,m);
85     print();
86   }
87 }
88
89 int main()
90 {
95 }