描述

小岛: 什么叫做因数分解呢?
doc : 就是将给定的正整数n, 分解为若干个素数连乘的形式.
小岛: 那比如说 n=12 呢?
doc : 那么就是 12 = 2 X 2 X 3 呀.
小岛: 呜呜, 好难, 居然素数会重复出现, 如果分解后每一个素数都只出现一次, 我就会.

wish: 这样来说, 小岛可以正确分解的数字不多呀.
doc : 是呀是呀.
wish: 现在问题来了, 对于给定的k, 第 k 个小岛无法正确分解的数字是多少?

格式

输入格式

输入只有一行, 只有一个整数 k.

输出格式

输出只有一行, 只有一个整数, 表示小岛无法正确分解出来的第k个数字.

样例1

样例输入1

 
10

样例输出1

 
27

限制

对于30%的数据, k <= 2,000,000
对于100%的数据, 1 <= k <= 10,000,000,000

提示

前 10 个小岛无法正确分解出来的数字依次是: 4 8 9 12 16 18 20 24 25 27

莫比乌斯反演

小于x的可以正确分解的数字个数是 Σmu[i]*(x/i^2),算不能分解正确的只要把mu反一下就行

↑可以参照这里http://www.cnblogs.com/SilverNebula/p/5656771.html

AC记录喜+1

然而1A记录并没有喜+1,因为二分上界傻傻写成了k……用脚想都知道不可能

↓这个二分上界是从黄学长那里看来的233

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
#define LL long long
using namespace std;
const int mxn=;
LL read(){
LL x=,f=;char ch=getchar();
while(ch<'' || ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>='' && ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int pri[mxn],mu[mxn],cnt=;
bool vis[mxn];
void init(){
mu[]=;
for(int i=;i<mxn;i++){
if(!vis[i]){
pri[++cnt]=i;
mu[i]=;
}
for(int j=;j<=cnt && (LL)pri[j]*i<mxn;j++){
vis[pri[j]*i]=;
if(i%pri[j]==){mu[pri[j]*i]=;break;}
mu[pri[j]*i]=-mu[i];
}
}
return;
}
LL calc(LL x){
int m=sqrt(x);
LL res=;
for(int i=;i<=m;i++)
res+=x/((LL)i*i)*mu[i];
return res;
}
int main(){
int i,j;
init();
LL n=read();
LL l=n,r=25505460948LL;
LL ans;
while(l<=r){
LL mid=(l+r)>>;
if(calc(mid)>=n){ans=mid;r=mid-;}
else l=mid+;
}
cout<<ans<<endl;
return ;
}

Vijos1889 天真的因数分解的更多相关文章

  1. vijos1889:天真的因数分解

    题目链接 vijos1889:天真的因数分解 题解 同bzoj2440: [中山市选2011]完全平方数 就是改成了求有平方因子数,依旧考虑二分,只是把容斥系数取一下相反数,也就是把莫比乌斯函数求一个 ...

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

    https://vijos.org/p/1889 同BZOJ2440..,不过这题要求的是有因数因子的,所以莫比乌斯函数要稍微改一下 #include<algorithm> #includ ...

  3. VIJOS 1889 天真的因数分解 ——莫比乌斯函数

    同理BZOJ2440 二分答案,不过这次变成了统计含有平方因子的个数 #include <cmath> #include <cstdio> #include <cstri ...

  4. 数学#素数判定Miller_Rabin+大数因数分解Pollard_rho算法 POJ 1811&2429

    素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: h ...

  5. [LeetCode] Minimum Factorization 最小因数分解

    Given a positive integer a, find the smallest positive integer b whose multiplication of each digit ...

  6. 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 ...

  7. Pollard_rho 因数分解

    Int64以内Rabin-Miller强伪素数测试和Pollard 因数分解的算法实现 选取随机数\(a\) 随机数\(b\),检查\(gcd(a - b, n)\)是否大于1,若大于1则\(a - ...

  8. @总结 - 10@ Miller-Rabin素性测试与Pollard-Rho因数分解

    目录 @1 - 素性测试:Miller-Rabin算法@ @1.1 - 算法来源@ @1.2 - 算法描述@ @1.3 - 算法实现@ @2 - 因数分解:Pollard-Rho算法@ @2.0 - ...

  9. iOS开发 - 一个天真的搜索控制器的独白

    文/Azen(简书作者)原文链接:http://www.jianshu.com/p/6d5327111511著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 正文 一.关于横向模块开发 ...

随机推荐

  1. Linux 删除文件中某一行的方法

    如果有一个abc.txt文件,内容是: aaa bbb ccc ddd eee fff 如果要删除aaa,那么脚本可以这样写: sed -i '/aaa/d' abc.txt 如果删除的是一个变量的值 ...

  2. 解决Gradle DSL method not found: ‘android()’

    最近导入as的项目出了这样的问题 这个问题困扰了我很长时间,好吧,搜了半天全都是runProguard的,最后在stackoverflow上搜到解决办法了: http://stackoverflow. ...

  3. Ubuntu优化-修改启动级别

    一 修改Ubuntu启动级别 sudo apt-get install sysv-rc-conf 执行: sysv-rc-conf 打x的表示开机启动. 二 启动级别 Ubuntu默认启动级别为2 r ...

  4. [转]SIFT特征提取分析

    SIFT(Scale-invariant feature transform)是一种检测局部特征的算法,该算法通过求一幅图中的特征点(interest points,or corner points) ...

  5. .net面试题(.Net+Html+Javascript)

    .net方面 1.简述 private. protected. public. internal 修饰符的访问权限. 2.override与重载的区别 3..net值类型和引用类型的区别,写出代码样例 ...

  6. Android调用基于.net的WebService

    在实际开发项目中,有时候会为Android开发团队提供一些接口,一般是以asmx文件的方式来承载.而公布出去的数据一般上都是标准的json数据.但是在实际过程中,发现Android团队那边并不是通过将 ...

  7. ant exec

    http://ant.apache.org/manual/Tasks/exec.html Exec Description Executes a system command. When the os ...

  8. [CareerCup] 5.1 Insert Bits 插入位

    5.1 You are given two 32-bit numbers, N and M, and two bit positions, land j. Write a method to inse ...

  9. [CareerCup] 8.8 Othello Game 黑白棋游戏

    8.8 Othello is played as follows: Each Othello piece is white on one side and black on the other. Wh ...

  10. linux内核分析 第4章读书笔记

    第四章 进程调度 一.抢占与非抢占 1.非抢占式进程调度 进程会一直执行直到自己主动停止运行 2.抢占式进程调度 Linux/Unix使用的是抢占式的方式,强制的挂起进程的动作就叫做抢占. 二.进程优 ...