VIJOS 1889 天真的因数分解(莫比乌斯反演,容斥原理)

https://vijos.org/p/1889

同BZOJ2440..,不过这题要求的是有因数因子的,所以莫比乌斯函数要稍微改一下

 #include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#define N 200000
#define ll long long
int mul[N+],mark[N+],p[N+];
ll K;
void init(){
mul[]=;
for (int i=;i<=N;i++){
if (!mark[i]){
p[++p[]]=i;
mul[i]=;
}
for (int j=;j<=p[]&&p[j]*i<=N;j++){
mark[i*p[j]]=;
if (i%p[j]) mul[i*p[j]]=-mul[i];
else{
mul[i*p[j]]=;
break;
}
}
}
}
ll cal(ll x){
ll sum=,t=sqrt(x);
for (ll i=;i<=t;i++){
sum+=x/(i*i)*mul[i];
}
return sum;
}
int main(){
scanf("%lld",&K);
init();
ll l=K,r=25505460948LL,ans=;
while (l<=r){
ll mid=(l+r)>>;
if (cal(mid)>=K) ans=mid,r=mid-;
else l=mid+;
}
printf("%lld\n",ans);
}
上一篇:DOS的几个常用命令


下一篇:codeforces 724