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

x/(p*p)即可

/**************************************************************
Problem: 2440
User: walfy
Language: C++
Result: Accepted
Time:5240 ms
Memory:1728 kb
****************************************************************/

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define ll long long
#define vi vector<int>
#define mod 1000000007
#define C 0.5772156649
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
#define pil pair<int,ll>
#define pli pair<ll,int>
#define pii pair<int,int>
#define cd complex<double>
#define ull unsigned long long
#define base 1000000000000000000
#define fio ios::sync_with_stdio(false);cin.tie(0)

using namespace std;

const double eps=1e-6;
const int N=50000+10,maxn=5000+10,inf=0x3f3f3f3f,INF=0x3f3f3f3f3f3f3f3f;

bool mark[N];
int prime[N],mu[N],cnt;
void init()
{
mu[1]=1;
for(int i=2;i<N;i++)
{
if(!mark[i])mu[i]=-1,prime[++cnt]=i;
for(int j=1;j<=cnt&&prime[j]*i<N;j++)
{
mark[i*prime[j]]=1;
mu[i*prime[j]]=-mu[i];
if(i%prime[j]==0){mu[i*prime[j]]=0;break;}
}
}
}
ll check(ll x)
{
//    printf("%lld\n",x);
ll ans=x;
for(ll i=2;i*i<=x;i++)ans+=x*mu[i]/(i*i);
return ans;
}
int main()
{
init();
int T;scanf("%d",&T);
while(T--)
{
ll x;
scanf("%lld",&x);
ll l=0,r=2e9;
while(l<r-1)
{
ll m=(l+r)>>1;
if(check(m)>=x)r=m;
else l=m;
}
printf("%lld\n",l+1);
}
return 0;
}
/********************

********************/

posted @ 2018-06-29 21:06  walfy  阅读(120)  评论(0编辑  收藏  举报