传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=2986
首先能想到二分答案,然后判断1~X中有多少个squarefree,这里用莫比乌斯函数来容斥即可。
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<bitset>
using namespace std;
typedef long long LL;
int miu[510000];
int prim[510000],primm;
bool valid[510000];
void mobius(int N)
{
miu[1]=1;
for (int i=2;i<=N;i++)
{
if (!valid[i]) prim[++primm]=i,miu[i]=-1;
for (int j=1;j<=primm&&i*prim[j]<=N;j++)
{
valid[i*prim[j]]=1;
if (i%prim[j]==0)
{
miu[i*prim[j]]=0;
break;
}
else miu[i*prim[j]]=-miu[i];
}
}
}
LL cal(LL x)
{
LL res=0;
for (LL i=1;i*i<=x;i++)
res+=x/i/i*(LL)miu[i];
return x-res;
}
LL ans,n;
int main()
{
cin>>n;
mobius(500000);
LL l=1,r=210000000000LL;
while (l<=r)
{
LL mid=(l+r)/2;
if (cal(mid)>=n) r=mid-1,ans=mid;
else l=mid+1;
}
cout<<ans<<endl;
return 0;
}