标签:cstring ima http long ace std using img 公式
自己是在是弱,看了半天才看懂题解
写公式实在是麻烦,搬家一份:


#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#define N 101000
#define pos(i,a,b) for(int i=(a);i<=(b);i++)
using namespace std;
#define LL long long
int t,n,m;
int notprime[N],prime[N],mu[N];
LL f[N];
void get_mu(){
notprime[1]=1;mu[1]=1;
pos(i,2,N-10){
if(!notprime[i]){
prime[++prime[0]]=i;
mu[i]=-1;
}
for(int j=1;j<=prime[0]&&prime[j]*i<=N-10;j++){
notprime[prime[j]*i]=1;
if(i%prime[j]==0){
mu[i*prime[j]]=0;
break;
}
mu[i*prime[j]]=-mu[i];
}
}
pos(i,1,N-10) mu[i]+=mu[i-1];
pos(i,1,N-10){
int last(0);
for(int j=1;j<=i;j=last+1){
last=i/(i/j);
f[i]+=(i/j)*1ll*(last-(j-1));
}
}
}
LL get_ans(){
int last(0);
LL res(0);
for(int i=1;i<=n;i=last+1){
last=min(n/(n/i),m/(m/i));
res+=f[n/i]*f[m/i]*(mu[last]-mu[i-1]);
}
return res;
}
int main(){
scanf("%d",&t);
get_mu();
while(t--){
scanf("%d%d",&n,&m);if(n>m) swap(n,m);
printf("%lld\n",get_ans());
}
return 0;
}
标签:cstring ima http long ace std using img 公式
原文地址:http://www.cnblogs.com/Hallmeow/p/8011100.html