题意简单粗暴,让你求 。
与gcd有关,一般来说都是要上莫比乌斯来反演一下了。具体来说,我们先来推一些式子:
那么,原式我们就可以写成:
然后我们再交换一下求和次序:
对于后面这个东西,我们可以发现,对于一个数字x^k,他能够被d整除,当且仅当,其中pi表示d分解质因子的每一个数字,ai表示对应pi的指数。那么我么令,那么最后的答案就是:
我们注意到,是欧拉函数和莫比乌斯函数的迪利克雷卷积,根据定理,积性函数的迪利克雷卷积也是积性函数,因此具有积性。而、和是类似于d分解质因子的形式,显然也是具有积性的,因此我们可以构造线性筛,在O(A)的时间复杂度内解决这道题。所谓积性,就是在互质的时候f(xy)=f(x)*f(y),关键是要求不互质的时候以及质数本身的表达式。
我们令,根据我们之前的推导:,那么有:
于是:
那么:
接下来再看这个,这个就是在分解质因子的过程中,记录一个deg,表示当前质因子的指数。每次这个质因子加一,当发现它%k之后是1,说明此时除以k向上取整会变大,于是乘上当前质因子。具体见代码:
#include<bits/stdc++.h>
#define LL long long
#define mod 998244353
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define INF 0x3f3f3f3f
#define sf(x) scanf("%d",&x)
#define sc(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr(x,n) memset(x,0,sizeof(x[0])*(n+5))
#define file(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
using namespace std;
const int N = 1e7 + 10;
unsigned int p[N],phmu[N],f2[N],f3[N],last[N],deg[N];
bool isp[N];
void init()
{
int sz=0;
phmu[1]=f2[1]=f3[1]=last[N]=1;
for(int i=2;i<N;i++)
{
if(!isp[i])
{
f2[i]=f3[i]=p[++sz]=i;
phmu[i]=i-2; last[i]=deg[i]=1;
}
for(int j=1;j<=sz&&(LL)i*p[j]<N;j++)
{
int x=i*p[j];
isp[x]=1;
if(i%p[j]==0)
{
last[x]=last[i];
deg[x]=deg[i]+1;
if (last[i]>1) phmu[x]=phmu[last[i]]*phmu[x/last[i]];
else
{
if (i>p[j]) phmu[x]=phmu[i]*p[j];
else phmu[x]=(p[j]-1)*(p[j]-1);
}
f2[x]=f2[i]*(deg[x]%2==1?p[j]:1);
f3[x]=f3[i]*(deg[x]%3==1?p[j]:1);
break;
} else
{
deg[x]=1;
last[x]=i;
f2[x]=f2[i]*f2[p[j]];
f3[x]=f3[i]*f3[p[j]];
phmu[x]=phmu[i]*phmu[p[j]];
}
}
}
}
int main()
{
init();
int T; sf(T);
while(T--)
{
int a,b,c;
sc(a,b,c);
unsigned int ans=0;
for(int i=1;i<=a;i++)
ans=(ans+phmu[i]*(a/i*(b/f2[i])*(c/f3[i])));
printf("%d\n",ans&((1<<30)-1));
}
return 0;
}