BZOJ2440 [中山市选2011]完全平方数

13
100
1234567

19
163
2030745

HINT

 1 #include<iostream>
2 #include<cstdio>
3 #include<algorithm>
4 #include<vector>
5 #include<cstdlib>
6 #include<cmath>
7 #include<cstring>
8 using namespace std;
9 #define maxn 200010
10 #define N 200000
11 #define llg long long
12 #define inf (llg)1e12
13 #define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
14 llg n,m,val,mobius[maxn],prime[maxn],cnt,bj[maxn],T;
15 llg l,r,mid,ans;
16
17 void init()
18 {
19     mobius[1]=1;
20     for (llg i=2;i<=N;i++)
21     {
22         if (!bj[i]) prime[++cnt]=i,mobius[i]=-1;
23         for (llg j=1;j<=cnt && prime[j]*i<=N;j++)
24         {
25             bj[i*prime[j]]=1;
26             if (i%prime[j]) mobius[i*prime[j]]=-mobius[i];
27             else
28             {
29                 mobius[i*prime[j]]=0;
30                 break;
31             }
32         }
33     }
34 }
35
36 bool check(llg x)
37 {
38     llg up=sqrt(x+0.5),tot=0;
39     for (llg i=1;i<=up;i++)
40     {
41         tot+=mobius[i]*(x/(i*i));
42     }
43     if (tot>=val) return 1;
44     else return 0;
45 }
46
47 int main()
48 {
49     yyj("a");
50     init();
51     cin>>T;
52     while (T--)
53     {
54         cin>>val;
55         l=1,r=inf;
56         while (l<=r)
57         {
58             mid=(l+r)>>1;
59             if (check(mid)) ans=mid,r=mid-1;else l=mid+1;
60         }
61         printf("%lld\n",ans);
62     }
63
64     return 0;
65 }

posted @ 2017-02-03 22:56  №〓→龙光←  阅读(229)  评论(0编辑  收藏  举报