BZOJ2693

http://www.lydsy.com/JudgeOnline/problem.php?id=2693

#include<cstdio>
typedef unsigned long long ll;
inline int min(int a,int b){
	return a<b?a:b;
}
ll ans,rev;
const int maxn=1e7;
const ll mod=1e8+9;
int pr[maxn];
bool ip[maxn+1];
ll f[maxn+1];
int n,m;
int T;
inline void shai_fa(){
	f[1]=1ll;
	for(register int i=2;i<=maxn;++i){
		if(!ip[i])
			f[pr[++pr[0]]=i]=mod-i+1;
		for(register int j=1;j<=pr[0]&&1ll*pr[j]*i<=maxn;++j){
			ip[i*pr[j]]=1;
			if(i%pr[j]==0){
				f[i*pr[j]]=f[i];
				break;
			}
			f[i*pr[j]]=1ll*f[i]*f[pr[j]]%mod;
		}
	}
	for(register int i=2;i<=maxn;++i)
		f[i]=(1ll*f[i]*i%mod+1ll*f[i-1])%mod;
}
inline ll fp(ll a,ll b){
	ll ret=1ll;
	while(b){
		if(b&1ll)ret=1ll*ret*a%mod;
		b>>=1ll;
		a=1ll*a*a%mod;
	}
	return ret;
}
int main(){
	shai_fa();
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&m);
		ans=0;
		for(register int i=1,pos;i<=min(n,m);i=pos+1){
			pos=min(n/(n/i),m/(m/i));
			ans=(ans+1ll*(1ll*(n/i+1)*(n/i)/2)%mod*(1ll*(m/i+1)*(m/i)/2%mod)%mod*(f[pos]-f[i-1]+mod)%mod)%mod;
		}
		printf("%lld\n",ans);
	}
	return 0;
} 

  

posted @ 2017-12-21 17:41  Stump  阅读(188)  评论(0编辑  收藏  举报