hdu6715

链接:hdu6715

题解

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define rep(i,x,y) for(register int i=x;i<=y;++i)
#define repd(i,x,y) for(register int i=x;i>=y;--i)
#define ll long long
using namespace std;
const int N=2e6+7;
ll mu[N],p[N],vis[N],cnt,n,m,T,a[N];
ll ans;
void get_mu(int n){
mu[1]=1;
rep(i,2,n){
if(!vis[i])mu[i]=-1,p[++cnt]=i;
for(int j=1;j<=cnt&&i<=n/p[j];++j){
vis[i*p[j]]=1;
if(i%p[j]==0)break;
mu[i*p[j]]-=mu[i];
}
}
rep(i,1,n)for(int j=i;j<=n;j+=i)a[j]+=mu[i]*mu[j/i];
}
int main(){
scanf("%d",&T);
get_mu(1e6+7);
while(T--&&~scanf("%d%d",&n,&m)){
if(n>m)swap(n,m);
ans=0;
rep(i,1,n){
int b=0,c=0;
for(int j=i;j<=n;j+=i)b+=mu[j];
for(int j=i;j<=m;j+=i)c+=mu[j];
ans+=a[i]*b*c;
}
printf("%lld\n",ans);
}
return 0;
}