vijos1889:天真的因数分解
题目链接
题解
同bzoj2440: [中山市选2011]完全平方数
就是改成了求有平方因子数,依旧考虑二分,只是把容斥系数取一下相反数,也就是把莫比乌斯函数求一个反着的
详见上方题解链接
代码
#include<cmath>
#include<cstdio>
#include<algorithm>
const int maxn = 200007;
#define int long long
inline int read() {
int x = 0;
char c = getchar();
while(c < '0' || c > '9') c = getchar();
while(c <= '9' && c >= '0') x = x * 10 + c - '0',c = getchar();
return x;
}
int prime[maxn],mu[maxn];bool p[maxn];
void get_mu() {
//mu[1] = 1;
int n = maxn - 7,num = 0;
for(int i = 2;i <= n;++ i) {
if(!p[i]) prime[++num] = i,mu[i] = 1;
for(int j = 1;j <= num && prime[j] * i <= n;++ j) {
p[i * prime[j]] = 1;
if(i % prime[j] == 0) break;
mu[i * prime[j]] = -mu[i];
}
}
}
int check(int x) {
int ret = 0 ;
for(int i = 2;i <= sqrt(x); ++ i ) {
ret += mu[i] * (x / (i * i));
}
return ret;
}
main() {
get_mu();
int k = read();
int l = 1,r = 30000000000,ans;
// if(k == 1)puts("1");
while(l <= r) {
int mid = l + r >> 1;
if(check(mid) >= k) ans = mid,r = mid - 1;
else l = mid + 1;
}
printf("%lld\n",ans);
return 0;
}