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

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

$T\leq50,\ k\leq10^9$

$[1,\ n]$ 中不是完全平方数的正整数倍的数的个数

$\therefore$ 原式 $=$ $$n-\lfloor\frac{n}{22}\rfloor-\lfloor\frac{n}{32}\rfloor-\lfloor\frac{n}{52}\rfloor+\lfloor\frac{n}{62}\rfloor-\lfloor\frac{n}{72}\rfloor+\lfloor\frac{n}{102}\rfloor+\cdots$$

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const int maxn = 5e4 + 10;
int T, n, tot, p[maxn], mu[maxn];

void sieve() {
int t = 45000; mu[1] = 1;
for (int i = 2; i <= t; i++) {
if (!p[i]) mu[i] = -1, p[++tot] = i;
for (int j = 1; j <= tot && i * p[j] <= t; j++) {
p[i * p[j]] = 1;
if (i % p[j] == 0) {
mu[i * p[j]] = 0; break;
}
mu[i * p[j]] = -mu[i];
}
}
}

bool check(int x) {
int t = sqrt(x), res = x;
for (int i = 2; i <= t; i++) {
res += x / (i * i) * mu[i];
}
return res < n;
}

int main() {
scanf("%d", &T), sieve();
while (T--) {
scanf("%d", &n);
ll l = n, r = n << 1, mid, res;
while (l <= r) {
check(mid = (l + r) >> 1) ? l = mid + 1 : r = (res = mid) - 1;
}
printf("%d\n", (int)res);
}
return 0;
}

posted @ 2019-01-31 13:34  cnJuanzhang  阅读(101)  评论(0编辑  收藏  举报