# BZOJ2440 完全平方数

4
1
13
100
1234567

1
19
163
2030745

### Hint

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<complex>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<ctime>
#include<queue>
#include<iomanip>
#define ll long long

using namespace std;
inline int Get() {int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}while('0'<=ch&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}

int T,k;
int pri[100005];
bool vis[100005];
int mu[100005];
void pre(int n) {
mu[1]=1;
for(int i=2;i<=n;i++) {
if(!vis[i]) {
mu[i]=-1;
pri[++pri[0]]=i;
}
for(int j=1;j<=pri[0]&&1LL*i*pri[j]<=n;j++) {
vis[i*pri[j]]=1;
if(i%pri[j]==0) {
mu[i*pri[j]]=0;
break;
}
mu[i*pri[j]]=-mu[i];
}
}
}

ll l,r,mid;
bool Check(ll n) {
ll maxx=sqrt(n)+1;
ll ans=0;
for(int i=2;i<=maxx;i++) {
ans-=n/(1ll*i*i)*mu[i];
}
return n-ans>=k;
}

int main() {
pre(100000);
T=Get();
while(T--) {
k=Get();
l=1,r=3e9;
while(l<r) {
mid=l+r>>1;
if(Check(mid)) r=mid;
else l=mid+1;
}
cout<<l<<"\n";
}
return 0;
}

posted @ 2018-11-21 08:37  hec0411  阅读(128)  评论(0编辑  收藏  举报