# BZOJ 2440 [中山市选2011]完全平方数 二分+容斥

$O(T*logn*\sqrt{n})$

#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
#define ull unsigned long long
#define ll long long
#define R register ll
#define pause (for(R i=1;i<=10000000000;++i))
#define In freopen("NOIPAK++.in","r",stdin)
#define Out freopen("out.out","w",stdout)
static char B[1<<15],*S=B,*D=B;
#ifndef JACK
#endif
inline int g() {
R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch=='-'?-1:fix;
if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix;
} inline bool isempty(const char& ch) {return (ch<=36||ch>=127);}
inline void gs(char* s) {
register char ch; while(isempty(ch=getchar()));
do *s++=ch; while(!isempty(ch=getchar()));
}

namespace Luitaryi {
const int N=32000;
int mu[N],pri[N/6],cnt,T,k;
bool vis[N];
inline void PRE() { mu[1]=1;
for(R i=2;i<=N-10;++i) {
if(!vis[i]) pri[++cnt]=i,mu[i]=-1;
for(R j=1;j<=cnt&&i*pri[j]<=N-10;++j) {
vis[i*pri[j]]=true;
if(i%pri[j]==0) break;
mu[i*pri[j]]=-mu[i];
}
}
}
inline bool ck(int x) { R ret=0;
for(R i=1,lim=sqrt(x);i<=lim;++i) ret+=mu[i]*(x/(i*i));
return ret>=k;
}
inline void main() { PRE();
T=g(); while(T--) {
k=g();
R l=1,r=k<<1;
while(l<r) {
R md=l+r>>1;
if(ck(md)) r=md;
else l=md+1;
} printf("%lld\n",l);
}
}
}
signed main() {
Luitaryi::main();
}

2019.07.17

posted @ 2019-07-17 22:59  LuitaryiJack  阅读(139)  评论(0编辑  收藏  举报