题解:
莫比乌斯反演
ans=sigma(x/(i*i)*miu[i])
代码:
#include<bits/stdc++.h> using namespace std; const int N=44723; int T,n,flag[N],p[N],tot,miu[N]; void init() { miu[1]=1; for (int i=2;i<N;i++) { if (!flag[i]) { miu[i]=-1; p[++tot]=i; } for (int j=1;j<=tot;j++) { int k=p[j]*i; if (k>=N)break; flag[k]=1; if (i%p[j]==0) { miu[k]=0; break; } miu[k]-=miu[i]; } } } int pd(int x) { int ans=0; for (int i=1;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=0,r=2*n; while (l<r) { int mid=((long long)l+r+1)/2; if (!pd(mid))l=mid; else r=mid-1; } printf("%d\n",l+1); } }