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;
}
vijos1889:天真的因数分解的更多相关文章
- Vijos1889 天真的因数分解
描述 小岛: 什么叫做因数分解呢?doc : 就是将给定的正整数n, 分解为若干个素数连乘的形式.小岛: 那比如说 n=12 呢?doc : 那么就是 12 = 2 X 2 X 3 呀.小岛: 呜呜, ...
- VIJOS 1889 天真的因数分解(莫比乌斯反演,容斥原理)
https://vijos.org/p/1889 同BZOJ2440..,不过这题要求的是有因数因子的,所以莫比乌斯函数要稍微改一下 #include<algorithm> #includ ...
- VIJOS 1889 天真的因数分解 ——莫比乌斯函数
同理BZOJ2440 二分答案,不过这次变成了统计含有平方因子的个数 #include <cmath> #include <cstdio> #include <cstri ...
- 数学#素数判定Miller_Rabin+大数因数分解Pollard_rho算法 POJ 1811&2429
素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: h ...
- [LeetCode] Minimum Factorization 最小因数分解
Given a positive integer a, find the smallest positive integer b whose multiplication of each digit ...
- POJ 1811 Prime Test (Rabin-Miller强伪素数测试 和Pollard-rho 因数分解)
题目链接 Description Given a big integer number, you are required to find out whether it's a prime numbe ...
- Pollard_rho 因数分解
Int64以内Rabin-Miller强伪素数测试和Pollard 因数分解的算法实现 选取随机数\(a\) 随机数\(b\),检查\(gcd(a - b, n)\)是否大于1,若大于1则\(a - ...
- @总结 - 10@ Miller-Rabin素性测试与Pollard-Rho因数分解
目录 @1 - 素性测试:Miller-Rabin算法@ @1.1 - 算法来源@ @1.2 - 算法描述@ @1.3 - 算法实现@ @2 - 因数分解:Pollard-Rho算法@ @2.0 - ...
- iOS开发 - 一个天真的搜索控制器的独白
文/Azen(简书作者)原文链接:http://www.jianshu.com/p/6d5327111511著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 正文 一.关于横向模块开发 ...
随机推荐
- 【LA】5135 Mining Your Own Business
[算法]点双连通分量 [题解]详见<算法竞赛入门竞赛入门经典训练指南>P318-319 细节在代码中用important标注. #include<cstdio> #includ ...
- .NET FrameWork 中的 CTS
CTS:Common Type System 通用类型系统. 1.不仅可以把C#编译成.Net IL,还支持Basic.Python.Ruby等语言,甚至还支持Java.不同语言中的数据类型定义是不一 ...
- 如果你也想写个完整的 Vue 组件项目
1.一个完整的组件项目需要什么? 必要的: 组件构建方式 ( webpack / rollup 之类 ),并提供至少一个主流的输出格式 (ESModule) Demo 及 Demo 源码 文档,可以是 ...
- python初步学习-python数据类型之strings(字符串)
数据类型-字符串 字符串是 Python 中最常用的数据类型.我们可以使用引号(''或者"")来创建字符串 var1 = 'Hello World!' var2 = "P ...
- C# 关于调用微信接口的代码
调用微信接口前需要准备的内容. 1.微信公众平台的appid 2.微信公众平台的secret 3..获取tokenid 4.获取ticket 5.生成签名的随机串 6.生成签名的时间戳 7.生成签名 ...
- C后端设计开发 - 第5章-内功-数据结构下卷
正文 第5章-内功-数据结构下卷 后记 如果有错误, 欢迎指正. 有好的补充, 和疑问欢迎交流, 一块提高. 在此谢谢大家了.
- vue点击切换颜色限制个数(用了mui框架)
vue点击切换颜色 只能点击一个 <!doctype html> <head> <meta charset="UTF-8"> <title ...
- java中String的内存位置
- Centos7 环境准备
Centos7 环境准备 #关闭防火墙 systemctl stop firewalld systemctl disable firewalld #关闭selinux sed -i 's/SELINU ...
- maven添加jar包到本地仓库
mvn install:install-file -Dfile=desutill.jar -DgroupId=com.bfd -DartifactId=des -Dversion=1.0 -Dpack ...