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

## 2440: [中山市选2011]完全平方数

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 883  Solved: 425
[Submit][Status]

4
1
13
100
1234567

1
19
163
2030745

,    T ≤ 50

## Source

 1 #include<cstdio>
2 #include<cstdlib>
3 #include<cmath>
4 #include<cstring>
5 #include<algorithm>
6 #include<iostream>
7 #include<vector>
8 #include<map>
9 #include<set>
10 #include<queue>
11 #include<string>
12 #define inf 1000000000
13 #define maxn 200000
14 #define maxm 500+100
15 #define eps 1e-10
16 #define ll long long
17 #define pa pair<int,int>
18 #define for0(i,n) for(int i=0;i<=(n);i++)
19 #define for1(i,n) for(int i=1;i<=(n);i++)
20 #define for2(i,x,y) for(int i=(x);i<=(y);i++)
21 #define for3(i,x,y) for(int i=(x);i>=(y);i--)
22 using namespace std;
24 {
25     int x=0,f=1;char ch=getchar();
26     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
27     while(ch>='0'&&ch<='9'){x=10*x+ch-'0';ch=getchar();}
28     return x*f;
29 }
30 int p[maxn],mu[maxn];
31 ll n;
32 bool check[maxn];
33 void get()
34
35 {
36
37     int tot=0;
38
39     mu[1]=1;
40
41     for2(i,2,maxn)
42
43     {
44
45         if(!check[i])p[++tot]=i,mu[i]=-1;
46
47         for1(j,tot)
48
49          {
50
51              int k=p[j]*i;
52
53              if(k>maxn)break;
54
55             check[k]=1;
56
57             if(i%p[j])mu[k]=-mu[i];else {mu[k]=0;break;}
58
59          }
60
61     }
62
63 }
64 inline bool test(ll x)
65 {
66     ll t=0;
67     for1(i,(int)sqrt(x))t+=mu[i]*(x/(i*i));
68     return t>=n;
69 }
70 int main()
71 {
72     freopen("input.txt","r",stdin);
73     freopen("output.txt","w",stdout);
74     get();
76     while(cs--)
77     {
79         while(l<=r)
80         {
81             mid=(l+r)>>1;
82             if(test(mid))r=mid-1;else l=mid+1;
83         }
84         printf("%lld\n",l);
85     }
86     return 0;
87 }
View Code

posted @ 2014-09-15 18:54  ZYF-ZYF  Views(314)  Comments(3Edit  收藏  举报