# 【BZOJ2693】jzptab

## Output

T行 每行一个整数 表示第i组数据的结果

1
4 5

## Sample Output

122
HINT
T <= 10000
N, M<=10000000

#include <cstdio>
#include <cstring>
#include <iostream>
#define mod 100000009
using namespace std;
const int maxm=10000000;
typedef long long ll;
bool np[maxm+10];
int pri[maxm/10],mu[maxm+10];
ll sm[maxm+10];
int num,T;
int main()
{
ll i,j,x,y,last,ans;
sm[1]=mu[1]=1;
for(i=2;i<=maxm;i++)
{
if(!np[i])	pri[++num]=i,mu[i]=-1,sm[i]=-i+1+mod;
for(j=1;j<=num&&i*pri[j]<=maxm;j++)
{
np[i*pri[j]]=1;
if(i%pri[j]==0)
{
sm[i*pri[j]]=sm[i];
mu[i*pri[j]]=0;
break;
}
mu[i*pri[j]]=-mu[i];
sm[i*pri[j]]=(sm[i]-sm[i]*pri[j]%mod+mod)%mod;
}
}
for(i=1;i<=maxm;i++)	sm[i]=(sm[i-1]+sm[i]*i%mod+mod)%mod;
scanf("%d",&T);
while(T--)
{
scanf("%lld%lld",&x,&y),ans=0;
if(x<y)	swap(x,y);
for(i=1;i<=y;i=last+1)
{
last=min(x/(x/i),y/(y/i));
ans=(ans+(sm[last]-sm[i-1]+mod)%mod*((x/i*(x/i+1)>>1)%mod)%mod*((y/i*(y/i+1)>>1)%mod)%mod+mod)%mod;
}
printf("%lld\n",ans);
}
return 0;
}

| 欢迎来原网站坐坐！ >原文链接<

posted @ 2017-06-13 09:19  CQzhangyu  阅读(196)  评论(0编辑  收藏  举报