You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.

Divisor of n is any such natural number, that n can be divided by it without remainder.

Input

The first line contains two integers n and k (1 ≤ n ≤ 1015, 1 ≤ k ≤ 109).

Output

If n has less than k divisors, output -1.

Otherwise, output the k-th smallest divisor of n.

Examples
input
4 2
output
2
input
5 3
output
-1
input
12 5
output
6
Note

In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.

In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, so the answer is -1.

solution

原本想了个分解质因数后递推,但发现空间不够

其实可以用时间换空间,暴力嘛

随便做一做就行了

#include <math.h>
#include <vector>
#include <stdio.h>
#define L long long
char B[],*p=B,pb[];
inline void Rin(register L &x){
x=;
while(*p<''||*p>'')p++;
while(*p>=''&&*p<='')
x=x*10LL+*p++-'';
}
inline void Mo(register L x){
register int top=;
while(x)pb[++top]=(x%10LL)+'',x/=10LL;
while(top)putchar(pb[top--]);
putchar('\n');
}
L n,K,s,l1,l2;
std::vector<L>p1,p2;
int main(){
fread(B,,,stdin);
Rin(n),Rin(K);
L s=sqrt(n);
for(register L i=;i<s;i++)
if(n%i==0LL){
p1.push_back(i);
p2.push_back(n/i);
}
if(s*s==n)
p1.push_back(s);
else
if(n%s==){
p1.push_back(s);
p2.push_back(n/s);
}
l1=p1.size(),l2=p2.size();
if(l1+l2<K)
puts("-1");
else{
if(K<=l1)
Mo(p1[K-]);
else
Mo(p2[l2-K+l1]);
}
return ;
}

最新文章

  1. Jmeter发送soap请求
  2. Unity3D 之 iTween 相关
  3. Visual Studio 技能GET
  4. LED应用照明产品常识关键点
  5. Windows 8.1 新增控件之 AppBar
  6. 事件监听addEventListener()和removeEventListener() ---------1
  7. hbase 停止regionserver
  8. Vue.js学习 Item12 – 内部响应式原理探究
  9. 20. Screen
  10. R与数据分析旧笔记(十)非线性模型
  11. POJ 2914 Minimum Cut 最小割图论
  12. Chrome 里的请求报错 &quot;CAUTION: Provisional headers are shown&quot; 是什么意思?
  13. linux下初始化mysql时报错
  14. SSRF漏洞浅析
  15. mysql入门学习笔记
  16. python多线程-共享全局变量
  17. HDU 1175 连连看 (DFS+剪枝)
  18. DotNetty项目基本了解和介绍
  19. js检查字符串的包含关系
  20. sqlite 数据库错误 The database disk image is malformed database disk image

热门文章

  1. bzoj2440 [中山市选2011]完全平方数——莫比乌斯+容斥
  2. oracle 统计/分析函数
  3. EJB是什么?EJB的概念分析与理解(copy)
  4. 栗染-git命令搭建简单的个人的网页
  5. object-c中实现特定一个或者多个页面横竖屏,其他界面保持竖屏显示。
  6. 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers
  7. iPhone4到iPhone6的设计、制造工艺历程浅析
  8. HTML空格占位
  9. Laravel5.1学习笔记21 EloquentORM 集合
  10. CF848A From Y to Y