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

http://www.elijahqi.win/archives/1330
Description

Input

Output

Sample Input
4
1
13
100
1234567
Sample Output
1
19
163
2030745
HINT

, T ≤ 50 同vijos 1889注意 二分相加会爆Int

#include<cstdio>
#include<cmath>
#define N 1100000
inline char gc(){
static char now[1<<16],*S,*T;
return *S++;
}
int x=0;char ch=gc();
while (ch<'0'||ch>'9') ch=gc();
while (ch<='9'&&ch>='0'){x=x*10+ch-'0';ch=gc();}
return x;
}
int mu[N],prime[N],not_prime[N],T,k,top;
inline bool check(int x){
int nn=sqrt(x);long long ans=0,last=0;
for (int i=2;i<=nn;i=last+1){
last=sqrt(x/(x/(i*i)));
ans+=(mu[last]-mu[i-1])*(x/(i*i));
}return ans+x>=k;
}
int main(){
freopen("bzoj2440.in","r",stdin);
for (int i=2;i<=1e6;++i){
if (!not_prime[i]){
prime[++top]=i;mu[i]=-1;
}
for (int j=1;prime[j]*i<=1e6;++j){
not_prime[i*prime[j]]=1;
if (i%prime[j]==0){
mu[i*prime[j]]=0;break;
}mu[i*prime[j]]=-mu[i];
}
}
for (int i=1;i<=1e6;++i) mu[i]+=mu[i-1];
while (T--){
while (l<=r){
int mid=(long long)l+r>>1;
if (check(mid)) r=mid-1;else l=mid+1;
}
printf("%d\n",l);
}
return 0;
}



• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120