【BZOJ】【2440】【中山市选2011】完全平方数

时间:2023-03-08 23:38:01
【BZOJ】【2440】【中山市选2011】完全平方数

莫比乌斯函数/容斥原理

  PoPoQQQ讲义引入例题= =

  比较水……就是莫比乌斯函数的简单应用,也可理解为乱容斥一下……

  二分答案——>求1~x有多少个无平方因子的数Q(x)。

引用一下PoPoQQQ的题解:

•根据容斥原理可知 对于sqrt(x)以内所有的质数 有
•  x以内的无平方因子数
•=0个质数乘积的平方的倍数的数的数量(1的倍数)
•-每个质数的平方的倍数的数的数量(9的倍数,25的倍数,...)
•+每2个质数乘积的平方的倍数的数的数量(36的倍数,100的倍数,...)-...
•容易发现每个乘积a前面的符号恰好是aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFMAAAAyCAIAAACveHCoAAACFElEQVRoge3a0bmDIAwG0MzFQMzDNCzDMN6HVkWU5A9EvP0wr9qQIwiKpWXWoKcLeCxe+XzxyueLVz5fPCdPwbmQnsvyiDwFR0Q+2mSLnoj0/OFyW/UhqU4/Vn4LO0+twI+UR093uRvyD5N/+uRG97KsdqzjB8m/boPJ3KydMfJPX9wP3+hAUyr5mraWt3L86x4Bz2qQ7iuN/An4+uMiQfRVGkpXyDvh2sntdMum4MjHLV81HdggLu+Fa7q8MlGl4Jzjq8gL4emwXBJIcLzLmelwz8ZdR6xNVC7BK8f36w92OT83YyasUVDeCAc76XR67WTsFt7l3HmYvBWuk4trMThtZ3KmVUjeDMdqKM6V4VIu6Hoj8ma4Ri4PZBhuJm+HK0a7DFesEkbyHjgsF1d9bNbSnCvKu+BowdLDR5YGeC6wWdX64OoV+DJL9ORCwJ/+TZ5kuNGad8R2OPrais6VzPRS9ORCKlb6FELdBD498fL8Tal8VSIXUtnIyb0gc9exoeMrypY4S5KCg3Lxw4OVH+B5rDkP3V7DQfQyU1F6luPq6l5man9LXS/5oagiHbRgg/skl3fP+ZgAMtiZyMZad/zUbpTtFvHv7EDa7xEPsffvOt8zOjV1tYTuM8uVHH81uLc2XWg/LF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5CYII=" alt="" width="74" height="23" />故9对答案的贡献为负;aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAAAxCAIAAACdyjZMAAACc0lEQVR4nO2b2wGDIAxFmcuBnMdpXMZh7If1UUrIDQUSbe5nBYF7EMKjYXWpKmhX4N/lAJTlAJTlAJTlAJTlAJTlAJTlAJSlBmAewzgLEp/asonyK2iZhrOyGWkAmMcQwjAtfMp3K67GR6+xRuGjq1gEgJt/NiXTCFMQ5jGEYVqyveZLXQHA7p9t4L01xeAtqPNs6gcANkri/jWDIQaCJvQCsNnP9/6z6tA49ZnLDAJzAN6fJFubMvslJfSRMQD7iMhVptx+QSFd1AjA8VrCn/Tz41euLoKZK5fdAoE2AH70n+nVl+CtzEK0oB5qAqCv//GCBrD1yKJPoAWAo3nEKxn/mZp8LF6i5BcW2ZeIppCvAjGBbBsAKPMfHtfPdMkmYuOTZBK5G4BC/9FOyRvMEILT9FF1AIX+w5YA6YCP4Od5vJpqAyj1vyYA4Gt6LIBi/2EA0FDFDvFPBVDuPz4qIyEk26qHAuD8z3kHR4ZIjdklhSQOvU8UBPuffA5HhkCV9ySkCY8MQ7mxgXku6JQc6T0BECdpR6EVAWQH8et2wf54HqmVAL4XnVuLIXOEuv/1ACRuI1x+H+e408X2r0Jb9vKo6TzXHEP+VwPwtSMWw4hH0mTbZfvECQbYeRcNr7tSQwOlHADklF+yRQDHhrmtuVxlRYU0EN1haXtoAMs0VOtO7Q8MbR1JCkQCqOn/ih/Kl8naobxAFID6t202k1oguLH9FAAu5C5UkztUm/33dH9NA4CP0QtUmcHN3V9TANovKCtBuL/565oCwG4J1NGv18utX09HRX0BBpYz/yH/h4yyHICyHICyHICyHICyHICyHICyXlapXv3d1AXDAAAAAElFTkSuQmCC" alt="" width="55" height="21" />,故36对答案的贡献为正)
•x以内i^2的倍数有aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAABbCAIAAACnLa/SAAAB+klEQVR4nO2ayZXDIAxA1UD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IVhzv5KWtEj3gIthVYCrN5AAi3JNXCPdPYHrBii2+hWCgQ6SCsbbINwGCgQ7RZjDOkmAdEAx0iFKwgovbIRjoEKVgBb/GQzDQIbop3CVnuyTvFIKBNlEJVnQ2GQQDHaIRrOxsTQjWM/4T4htFIVjh2dAQrBWYy+25vxJwL+SClV5tAMG6pof12h6In7v47pgQrGsgGI/yu89CsAaQ/24ZBGPB3CLfAgjWCPt9NNITgvdvXwjGgblFvgkQrA2EpkAw9lEhELfItwGCNYFUFAjGQfqDqhogWAuIPYFgrQPBGuAcBPTBcvTz3BCsPtppCV1UNFv6eW4IVp15fGQlyV6r/VQ0W/p5bghWG+niP8LvTt4XCAaAI4Stg4rpp7gXCAbaBIIBAHJAMAAcgWAAOALBAHAEggHgCAQDwJH/gPIgepFUzWYAAAAASUVORK5CYII=" alt="" width="136" height="53" />
 /**************************************************************
Problem: 2440
User: Tunix
Language: C++
Result: Accepted
Time:2360 ms
Memory:10060 kb
****************************************************************/ //BZOJ 2440
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define rep(i,n) for(int i=0;i<n;++i)
#define F(i,j,n) for(int i=j;i<=n;++i)
#define D(i,j,n) for(int i=j;i>=n;--i)
using namespace std; int getint(){
int v=,sign=; char ch=getchar();
while(ch<''||ch>'') {if (ch=='-') sign=-; ch=getchar();}
while(ch>=''&&ch<='') {v=v*+ch-''; ch=getchar();}
return v*=sign;
}
/*******************tamplate********************/
const int N=1e6+;
typedef long long LL;
int mu[N],prime[N];
bool check[N];
void getmu(int n){
int tot=;
mu[]=;
for(int i=;i<n;++i){
if (!check[i]){
prime[tot++]=i;
mu[i]=-;
}
rep(j,tot){
if (i*prime[j]>n) break;
check[i*prime[j]]=;
if (i%prime[j]) mu[i*prime[j]]=-mu[i];
else{
mu[i*prime[j]]=;
break;
}
}
}
}
int judge(int x){
int ans=;
for(int i=;i*i<=x;i++)
ans+=mu[i]*((LL)x/(i*i));
return ans;
}
int main(){
int T=getint(),n;
getmu(N-);
while(T--){
n=getint();
int l=,r=n*,mid=,now=;
while(l<r){
mid=l+(r-l>>);
now=judge(mid);
if (now<n) l=mid+;
else r=mid;
}
printf("%d\n",l);
}
return ;
}