code:
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> #include<cmath> #include<algorithm> #include<queue> #include<set> #include<map> #include<iomanip> using namespace std; #define LL long long #define up(i,j,n) for(LL i=j;i<=n;i++) #define pii pair<LL,LL> #define db double #define eps 1e-4 #define FILE "dealing" LL read(){ LL x=0,f=1,ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0',ch=getchar();} return x*f; } const LL maxn=(LL)(1e7+3),inf=1000000000000000LL,limit=(LL)(1e7+2),mod=100000009; bool cmin(LL& a,LL b){return a>b?a=b,true:false;} bool cmax(LL& a,LL b){return a<b?a=b,true:false;} LL n,m; LL mu[maxn],b[maxn],H[maxn],prime[2000000],tail=0; LL sum(LL x,LL y){ x%=mod,y%=mod; return ((((x+1)*x)>>1)%mod)*((((y+1)*y)>>1)%mod)%mod; } void getmu(){ mu[1]=1;H[1]=1; up(i,2,limit){ if(!b[i])prime[++tail]=i,H[i]=(i-i*i)%mod; for(LL j=1;prime[j]*i<=limit;j++){ b[i*prime[j]]=1; if(i%prime[j]){ H[i*prime[j]]=(H[i]*H[prime[j]])%mod; } else { H[i*prime[j]]=H[i]*prime[j]; break; } } } up(i,1,limit)H[i]=(H[i]+H[i-1])%mod; } int main(){ freopen(FILE".in","r",stdin); freopen(FILE".out","w",stdout); LL q=read(); getmu(); while(q--){ n=read(),m=read(); if(n>m)swap(n,m); LL ans=0; up(i,1,n){ LL pos=min(n/(n/i),m/(m/i)); ans+=(H[pos]-H[i-1])*sum(n/i,m/i)%mod; ans%=mod; i=pos; } printf("%lld ",(ans+mod)%mod); } return 0; }