bzoj2440

时间:2022-01-03 15:52:06

题解:

莫比乌斯反演

ans=sigma(x/(i*i)*miu[i])

代码:

#include<bits/stdc++.h>
using namespace std;
const int N=;
int T,n,flag[N],p[N],tot,miu[N];
void init()
{
miu[]=;
for (int i=;i<N;i++)
{
if (!flag[i])
{
miu[i]=-;
p[++tot]=i;
}
for (int j=;j<=tot;j++)
{
int k=p[j]*i;
if (k>=N)break;
flag[k]=;
if (i%p[j]==)
{
miu[k]=;
break;
}
miu[k]-=miu[i];
}
}
}
int pd(int x)
{
int ans=;
for (int i=;i<=sqrt(x);i++)ans+=miu[i]*(x/(i*i));
return ans>=n;
}
int main()
{
scanf("%d",&T);
init();
while (T--)
{
scanf("%d",&n);
int l=,r=*n;
while (l<r)
{
int mid=((long long)l+r+)/;
if (!pd(mid))l=mid;
else r=mid-;
}
printf("%d\n",l+);
}
}