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

4
1
13
100
1234567

1
19
163
2030745

## HINT

对于 100%的数据有 1 ≤ Ki ≤ 10^9,  T ≤ 50

/**************************************************************
Problem: 2440
User: waz
Language: C++
Result: Accepted
Time:5560 ms
Memory:1992 kb
****************************************************************/

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>

const int maxn = 100010;

int prime[maxn], mu[maxn], flag[maxn], pt;

void init() {
mu[1] = 1;
for(int i = 2; i <= maxn; i++) {
if(!flag[i]) {
prime[++pt] = i;
mu[i] = -1;
}
for(int j = 1; j <= pt && prime[j]*i <= maxn; j++) {
flag[prime[j]*i] = 1;
mu[prime[j]*i]=mu[i]*mu[prime[j]];
if(i%prime[j] == 0)
mu[prime[j]*i] = 0;
}
}
}

int t; long long k;
//求解出小于等于x的数有多少无完全平方因子的数
long long get(long long x) {
long long res = 0;
for(long long i = 1; i*i <= x; i++) res += mu[i]*x/(i*i);
return res;
}

int main() {
init();
//int test = 2; printf("get(%d) = %d , %d\n", test, get(test), mu[test]);
scanf("%d", &t);
while(t--) {
scanf("%lld", &k);
long long l = 1, r = 3000000000ll;
while(l < r) {
long long mid = l+r>>1;
if(get(mid) < k)
l = mid + 1;
else r = mid;
}
printf("%lld\n", l);
}
return 0;
}


posted @ 2017-04-14 12:06  wazwaztime  阅读(142)  评论(0编辑  收藏  举报