A. k-th divisor

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input
output:standard output

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.

 //2017.02.01
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int divisor[]; int main()
{
long long n, k;
while(cin>>n>>k)
{
long long ans = -;
int cnt = ;
bool fg = false;
for(long long i = ; i*i <= n; i++)
{
if(n%i==)divisor[++cnt] = i;
if(i*i == n)fg = true;
}
if(fg && k > *cnt-)cout<<-<<endl;
else if(k > *cnt)cout<<-<<endl;
else if(k<=cnt)cout<<divisor[k]<<endl;
else{
if(!fg)cout<<(n/divisor[*cnt+-k])<<endl;
else cout<<(n/divisor[*cnt-k])<<endl;
}
} return ;
}

CodeForces762A的更多相关文章

  1. 在ubuntu下编写python

    一般情况下,ubuntu已经安装了python,打开终端,直接输入python,即可进行python编写. 默认为python2 如果想写python3,在终端输入python3即可. 如果需要执行大 ...

随机推荐

  1. AVFoundation - 拍照(Simple)

    1:基础 /* 1:获取可用输入设备 AVCaptureDevice 2:设置输入设备: [AVCaptureDeviceInput deviceInputWithDevice:self.captur ...

  2. Python网络通信

    day26 网络通信 参考: http://www.cnblogs.com/yuanchenqi/articles/5692716.html 男生是client端,字条是socket(sk),通过sk ...

  3. Lora通信解决方案对比

    欢迎大家进群交流分享:QQ群:773082801

  4. 逆向工程生成的Mapper.xml以及*Example.java详解

    逆向工程生成的接口中的方法详解 在我上一篇的博客中讲解了如何使用Mybayis逆向工程针对单表自动生成mapper.java.mapper.xml.实体类,今天我们先针对mapper.java接口中的 ...

  5. POJ 1014

    #include<iostream>#include<stdio.h>#define num 6using namespace std; bool DFS(int i,int ...

  6. Vue.js系列之三模板语法

    Vue.js 使用了基于 HTML 的模板语法,允许开发者声明式地将 DOM 绑定至底层 Vue 实例的数据.所有 Vue.js 的模板都是合法的 HTML ,所以能被遵循规范的浏览器和 HTML 解 ...

  7. Bloom分类法

    美国教育心理学家Bloom将教育的目标分为六类,从低到高,依次是:知识(Knowledge).理解(comprehension).应用(application).分析(analysis).综合(syn ...

  8. MySQL的Sleep进程占用大量连接解决方法

    第一部分为产生大量sleep进程的原理及对应解决方法第二部分为设置wait_timeout值,有效减少sleep进程 ========================================= ...

  9. Xshell用鼠标选中一段文字后自动换行的问题

    JavaScript   HTML(CSS) ASP 跨浏览器开发 IIS Apache vbScript JavaScript 应用服务器 XML/XSL 其他 CGI Ajax 非技术区 Cold ...

  10. 以整体思维看问题:解决单页应用,系统角色请求覆盖身份唯一标识(本项目中是session_id命名的)发送请求问题

    以前都是开始一段废话的,现在直接进入主题,首先介绍一下一些概念: 单页应用: 优点: 具有桌面应用的即时性.网站的可移植性和可访问性. 用户体验好.快,内容的改变不需要重新加载整个页面,web应用更具 ...