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著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 正文 一.关于横向模块开发 ...
随机推荐
- [CodeChef - GERALD07 ] Chef and Graph Queries
Read problems statements in Mandarin Chineseand Russian. Problem Statement Chef has a undirected gra ...
- 基本控件文档-UIKit结构图---iOS-Apple苹果官方文档翻译
本系列所有开发文档翻译链接地址:iOS7开发-Apple苹果iPhone开发Xcode官方文档翻译PDF下载地址 UIKit结构图 //转载请注明出处--本文永久链接:http://www.cnbl ...
- Tunnel Warfare(HDU1540+线段树+区间合并)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1540 题目: 题意:总共有n个村庄,有q次操作,每次操作分为摧毁一座村庄,修复一座村庄,和查询与询问的 ...
- java===java基础学习(9)---方法参数
方法参数注意三要点: 一个方法不能修改一个基本数据类型的参数(数值型或者布尔型). 一个方法可以改变一个对象参数的状态. 一个方法不能让对象参数引用一个新的对象. package testbotoo; ...
- python基础===时间处理模块
时间模块 Python中有很多方便我们处理时间信息的模块 time 模块 datetime 模块 pytz 模块 dateutil 模块 这里我们着重介绍的是前两种 time模块 time.time( ...
- OPENSOLARIS source
http://blog.csdn.net/nemo2011/article/details/8543220 http://fxr.watson.org/fxr/source/?v=OPENSOLARI ...
- sicily 1052. Candy Sharing Game
Constraints Time Limit: 1 secs, Memory Limit: 32 MB Description A number of students sit in a circle ...
- 【HDU3037】Saving Beans
Lucas的裸题,学习一个. #include<bits/stdc++.h> #define N 100010 using namespace std; typedef long long ...
- MySQL:按后缀缀批量删除表格
Select CONCAT( 'drop table ', table_name, ';' ) FROM information_schema.tables Where table_schema='s ...
- 《逐梦旅程 WINDOWS游戏编程之从零开始》笔记8——载入三维模型&Alpha混合技术&深度测试与Z缓存
第17章 三维游戏模型的载入 主要是如何从3ds max中导出.X文件,以及如何从X文件加载三维模型到DirextX游戏程序里.因为复杂的3D物体,要用代码去实现,那太反人类了,所以我们需要一些建模软 ...