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著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 正文 一.关于横向模块开发 ...
随机推荐
- 【BZOJ】1578: [Usaco2009 Feb]Stock Market 股票市场
[题意]给定s个股票和d天,给出价格矩阵s*d,每天可以买入或卖出整数倍股票,初始资金m,求最大利益.m<=200000,s<=50,d<=10. [算法]完全背包 [题解]关键在于 ...
- 【转载】VS2013安装需要IE10
因为需要移动办公,需要给笔记本搭建编程环境.安装VS2013时遇到了小麻烦,提示我,需要安装IE10. 然后我很听话的按照提供的超链接,到了官网,下载了最新的IE11,然后安装,结果告诉我下载的IE版 ...
- SQL SERVER 常用公式
SQL SERVER 获取当前月的天数 SELECT -DAY(getdate()+-DAY(getdate())) SQL server 除法计算百分比[整数乘1.0否则结果为0或1] CONVER ...
- HTML5获取地理位置信息并在Google Maps上显示
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8& ...
- ie6下双边距的问题
1.ie6双边距情况 <div class="red"></div> <div class="blue"></div& ...
- php中的__call()函数重载
<?php #调用类中没有的方法时, 会自动调用__call方法重载 #第一个参数是调用时的方法名, 第二个参数为参数组成的数组 class Cat{ public function Hello ...
- linux中使用mysql数据库
在安装完数据库后,如果没有设置root的mysql密码,在命令行输入mysql即可进入数据库 show databases;(有分号):查看当前存在的数据库 create database 名字:创建 ...
- Development tools[重点]
Development tools yum groupinfo "Development tools" Loaded plugins: product-id, security, ...
- 【Educational Codeforces Round 22】
又打了一场EDU,感觉这场比23难多了啊…… 艹还是我太弱了. A. 随便贪心一下. #include<bits/stdc++.h> using namespace std; ,ans=- ...
- leetcode 之Single Number(14)
这题并不难,但需要注意细节. ListNode* addTwo(ListNode *l1, ListNode *l2) { ListNode dummy(-); ; ListNode *prev = ...