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

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

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 4458  Solved: 2153
[Submit][Status][Discuss]

4
1
13
100
1234567

1
19
163
2030745

## HINT

,    T ≤ 50

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;
ll T, n, prime[50010], tot, mo[50010], vis[50010], ans;

void init()
{
mo[1] = 1;
for (ll i = 2; i <= 50000; i++)
{
if (!vis[i])
{
prime[++tot] = i;
mo[i] = -1;
}
for (ll j = 1; j <= tot; j++)
{
ll t = prime[j] * i;
if (t > 50000)
break;
vis[t] = 1;
if (i % prime[j] == 0)
{
mo[t] = 0;
break;
}
mo[t] = -mo[i];
}
}
}

ll check(ll x)
{
ll res = 0;
for (ll i = 1; i <= sqrt(x); i++)
res += mo[i] * (x / (i * i));
return res;
}

int main()
{
init();
scanf("%lld", &T);
while (T--)
{
ll l = 1, r = 1644934081, ans = 1;
scanf("%lld", &n);
while (l <= r)
{
ll mid = (l + r) >> 1;
if (check(mid) >= n)
{
ans = mid;
r = mid - 1;
}
else
l = mid + 1;
}
printf("%lld\n", ans);
}

return 0;
}

posted @ 2017-11-29 16:14  zbtrs  阅读(169)  评论(0编辑  收藏  举报