【bzoj2440】 中山市选2011—完全平方数
http://www.lydsy.com/JudgeOnline/problem.php?id=2440 (题目链接)
题意
求第K个不含有完全平方因子的数
Solution
没想到莫比乌斯还可以用来容斥,好6啊。右转题解→_→:LCF
蜜汁被狙人:jump
细节
LL,还TLE了2发。。。
代码
// bzoj2440 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #include<vector> #include<cmath> #define LL long long #define inf 2147483640 #define Pi acos(-1.0) #define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout); using namespace std; const int maxn=1000010; int mu[maxn],vis[maxn],p[maxn],K; int sigema(int k) { int ans=0; for (int i=1;i*i<=k;i++) ans+=mu[i]*(k/(i*i)); return ans; } int main() { mu[1]=1; for (int i=2;i<maxn;i++) { if (!vis[i]) p[++p[0]]=i,mu[i]=-1; for (int j=1;j<=p[0] && p[j]*i<maxn;j++) { vis[p[j]*i]=1; if (i%p[j]==0) {mu[p[j]*i]=0;break;} else mu[p[j]*i]=-mu[i]; } } int T;scanf("%d",&T); while (T--) { scanf("%d",&K); int l=0,r=inf,ans; while (l<=r) { int mid=((LL)l+r)>>1; if (sigema(mid)<K) l=mid+1; else ans=mid,r=mid-1; } printf("%d\n",ans); } return 0; }
This passage is made by MashiroSky.