# 题目分析

$\begin{split} ans &=\sum\limits_{d=1}^n d\cdot f(1)\\ &=\sum\limits_{d=1}^n d\cdot \sum\limits_{i=1}^{\lfloor\frac n d\rfloor}\mu(i)\cdot g(i)\\ &=\sum\limits_{d=1}^n d\cdot \sum\limits_{i=1}^{\lfloor\frac n d\rfloor}\mu(i)\cdot i\cdot i\cdot sum(\lfloor\frac n {di}\rfloor)\cdot sum(\lfloor\frac m {di}\rfloor)\\ &=\sum\limits_{i=1}^n\mu(i)\cdot i^2\sum\limits_{d=1}^{\lfloor\frac ni\rfloor}sum(\lfloor\frac n{di}\rfloor)\cdot sum(\lfloor\frac m{di}\rfloor)\cdot d\\ &=\sum\limits_{i=1}^n\mu(i)\cdot i^2\sum\limits_{i|T}^nsum(\lfloor\frac nT\rfloor)\cdot sum(\lfloor\frac mT\rfloor)\cdot \frac Ti\\ &=\sum\limits_{T=1}^nsum(\lfloor\frac nT\rfloor)\cdot sum(\lfloor\frac mT\rfloor)\sum\limits_{i|T}\mu(i)\cdot i^2\cdot \frac Ti\\ &=\sum\limits_{T=1}^nsum(\lfloor\frac nT\rfloor)\cdot sum(\lfloor\frac mT\rfloor)\sum\limits_{i|T}\mu(i)\cdot i\cdot T\\ &=\sum\limits_{T=1}^nsum(\lfloor\frac nT\rfloor)\cdot sum(\lfloor\frac mT\rfloor)\cdot T\sum\limits_{i|T}\mu(i)\cdot i\\ \end{split}$

# 代码实现

#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#define MAXN 0x7fffffff
typedef long long LL;
const int N=1e7+5,mod=1e8+9;
using namespace std;
inline int Getint(){register int x=0,f=1;register char ch=getchar();while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}return x*f;}
int g[N],prime[N];
bool vis[N];
int sum(int x){return 1ll*(1+x)*x/2%mod;}
int main(){
g[1]=1;
for(int i=2;i<=1e7;i++){
if(!vis[i])prime[++prime[0]]=i,g[i]=1-i;
for(int j=1;j<=prime[0]&&1ll*i*prime[j]<=1e7;j++){
vis[i*prime[j]]=1;
if(i%prime[j]==0){
g[i*prime[j]]=g[i];
break;
}
g[i*prime[j]]=(g[i]-1ll*prime[j]*g[i])%mod;
}
}
for(int i=1;i<=1e7;i++)g[i]=(1ll*g[i]*i+g[i-1])%mod;

int T=Getint();
while(T--){
int n=Getint(),m=Getint();
if(n>m)swap(n,m);
int ans=0;
for(int l=1,r;l<=n;l=r+1){
r=min(n/(n/l),m/(m/l));
ans=(ans+1ll*sum(n/l)*sum(m/l)%mod*(g[r]-g[l-1])%mod)%mod;
}
cout<<(ans+mod)%mod<<'\n';
}
return 0;
}

posted @ 2018-11-22 16:39  Emiya_2020  阅读(278)  评论(0编辑  收藏  举报