给定三个整数 A,B,C ,一个三元组 (i,j,k) 是合法的当且仅当满足:
∙ i,j,k 均为整数
∙ 1≤i≤A,1≤j≤B,1≤k≤C
∙ gcd(i,j)=gcd(i,k)=gcd(j,k)=1
请求出合法的三元组数量对 109+7 取模的结果。
1≤A,B,C≤5×104
大力推式子:
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
const int P=1000000007;
const int N=50000;
const int L=224;
const int M=20;
int pri[N+5],f[N+5],p[N+5],mu[N+5],ms[N+5],nxt[N+5],base[N+5],id[N+5],basans[N+5];
int S[N+5][L*3],T[N+5][L*3];
bool exist[N+5];
int bin[L*3];
int A,B,C,l,cnt1,cnt2,cnt;
void pre()
{
ms[1]=mu[1]=f[1]=base[1]=1;
for (int i=2;i<=C;++i)
{
if (!f[i]) pri[++pri[0]]=f[i]=base[i]=i,mu[i]=-1;
for (int j=1,x;j<=pri[0];++j)
{
if (1ll*pri[j]*i>C) break;
f[x=pri[j]*i]=pri[j],mu[x]=mu[i]*(f[x]==f[i]?0:-1),base[x]=base[i]*(f[x]==f[i]?1:f[x]);
if (!(i%pri[j])) break;
}
ms[i]=ms[i-1]+mu[i];
}
for (int i=1;i<=C;++i) if (base[i]==i) nxt[i]=i/f[i];
cnt=0;
for (int i=1;i<=B;++i) if (!exist[B/i]) exist[B/i]=1,bin[++cnt]=B/i;
for (int i=1;i<=C;++i) if (!exist[C/i]) exist[C/i]=1,bin[++cnt]=C/i;
sort(bin+1,bin+1+cnt);
for (int i=1;i<=cnt;++i) id[bin[i]]=i;
for (int i=1;i<=cnt;++i) S[1][i]=ms[bin[i]],T[1][i]=bin[i];
for (int i=2;i<=C;++i)
if (base[i]==i)
for (int j=1;j<=cnt;++j)
S[i][j]=(S[nxt[i]][j]+S[i][id[bin[j]/f[i]]])%P,T[i][j]=(T[nxt[i]][j]-T[nxt[i]][id[bin[j]/f[i]]]+P)%P;
}
int solve()
{
int ret=0;
for (int a=1;a<=A;++a)
{
if (!basans[base[a]])
for (int st=1,en,mus,mul,lst=0;st<=B&&st<=C;st=en,lst=mus)
{
en=min(B/(B/st),C/(C/st))+1,mus=S[base[a]][id[en-1]],mul=1ll*T[base[a]][id[B/st]]*T[base[a]][id[C/st]]%P;
(basans[base[a]]+=1ll*(mus-lst+P)*mul%P)%=P;
}
(ret+=basans[base[a]])%=P;
}
return ret;
}
int main()
{
freopen("triple.in","r",stdin),freopen("triple.out","w",stdout);
scanf("%d%d%d",&A,&B,&C);
if (B<=A&&B<=C) swap(A,B);
if (C<=A&&C<=B) swap(A,C);
if (C<=B) swap(B,C);
pre(),printf("%d\n",solve());
fclose(stdin),fclose(stdout);
return 0;
}