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. 输出图中顶点i到顶点j之间的所有简单路径

    简单路径(不包括环) DFS遍历以及回溯得到结果 void dfs(ALGraph graph, int v, int end, bool visit[], int path[], int cnt) ...

  2. webpack 4 入坑及爬坑记录

    一.安装 在本机安装好nodejs的基础上,window操作系统,cmd打开控制台,添加到创建的文件夹下 npm init //初始化npm npm install webpack --save-de ...

  3. xp——极限编程的几个方法

    最近阅读<Head First Java>一书时,看到极限编程(XP)的概念,觉得很有趣,摘抄下来以备后期继续学习. 极限编程(XP)是一种新型的软件开发方法论.他的构想是结合了许多种&q ...

  4. MySQL实例crash的案例分析

    [作者] 王栋:携程技术保障中心数据库专家,对数据库疑难问题的排查和数据库自动化智能化运维工具的开发有强烈的兴趣. [问题描述] 我们生产环境有一组集群的多台MySQL服务器(MySQL 5.6.21 ...

  5. WebDriverAPI(5)

    将当前浏览器截屏 测试网址 http://www.baidu.com Java语言版本实例 @Test public void captureScreenInCurrentWindows() { dr ...

  6. Maven使用常用命令

    > mvn clean 删除target文件夹 > mvn clean test 编译测试代码,默认被放到target/test-classes文件夹下面 > mvn clean c ...

  7. 【jQuery源码】事件委托

    jQuery的事件绑定有几个比较优秀的特点: 1. 可以绑定不限数量的处理函数 2. 事件可以委托到祖先节点,不必一定要绑到对应的节点,这样后添加的节点也照样能被处理. 3. 链式操作 下面主要分析事 ...

  8. css 实现元素长宽等比缩放

    实现思路(长宽比2:1): 以父级元素为基准, 子级 width:100%; (也就是父级宽度的 100%), padding-top:50% (也就是父级宽度的 50%, 根据 css 规范, pa ...

  9. css 边框颜色渐变的半圆

    1.需求有这么个东西,个人不习惯背景图片来解决,开始了css尝试. <!DOCTYPE html> <html> <head> <meta charset=& ...

  10. 通过spark-sql快速读取hive中的数据

    1 配置并启动 1.1 创建并配置hive-site.xml 在运行Spark SQL CLI中需要使用到Hive Metastore,故需要在Spark中添加其uris.具体方法是将HIVE_CON ...