# 【BZOJ 2440】[中山市选2011]完全平方数

4
1
13
100
1234567

1
19
163
2030745

## HINT

,    T ≤ 50

1 #include<cstdio>
2 #include<algorithm>
3 #include<cmath>
4 using namespace std;
5 const int N=50010;
6 int mu[N],pri[N],sum[N];
7 int tot,T,a,b,c,d,k,ans;
8 bool mark[N];
9 void pre(){
10     mu[1]=1;
11     for (int i=2;i<=50000;i++){
12         if (!mark[i]){
13             pri[++tot]=i;
14             mu[i]=-1;
15         }
16         for (int j=1;j<=tot&&pri[j]*i<=50000;j++){
17             mark[pri[j]*i]=1;
18             if(i%pri[j]==0) {
19                 mu[pri[j]*i]=0;break;
20             }else mu[pri[j]*i]=-mu[i];
21         }
22     }
23 };
24
25 bool calc(int x){
26     int y=sqrt(x);long long sum=0;
27     for (int i=1;i<=y;i++){
28         sum+=mu[i]*(x/(i*i));
29     }
30     if (sum>=k) return 1;return 0;
31 }
32
33 int main(){
34     pre();
35     scanf("%d",&T);
36     while(T--){
37         scanf("%d",&k);
38         long long l=k,r=1644934089;
39         while(l<r){
40             long long mid=(l+r)>>1;
41             if (!calc(mid))l=mid+1;
42             else r=mid,ans=mid;
43         }
44         printf("%d\n",ans);
45     }
46 }

posted @ 2016-02-13 21:51  Alisahhh  阅读(162)  评论(0编辑  收藏  举报