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. JavaScript基础流程控制(3)

    day51 参考:https://www.cnblogs.com/liwenzhou/p/8004649.html for循环 while循环 三元运算 a>b条件成立,选a,不成立选b

  2. FunDA(6)- Reactive Streams:Play with Iteratees、Enumerator and Enumeratees

    在上一节我们介绍了Iteratee.它的功能是消耗从一些数据源推送过来的数据元素,不同的数据消耗方式代表了不同功能的Iteratee.所谓的数据源就是我们这节要讨论的Enumerator.Enumer ...

  3. KBEngine 安装

    其实这篇的内容官方文档都有, 但是既然打算记录一下学习笔记, 也就先从安装开始了. 一 下载源代码 进入github下载最新release的源码压缩包. windows选择zip, 下载完成之后右键解 ...

  4. 设置pip源头地址

    更新pip源 1 . 可以直接在pip时加入参数 比如: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple mysqldb 2 . 修改默 ...

  5. 过虑器应用之1-设置request编码

    一:设置Post编码 post请求接收中文,需要在Servlet里写上 request.setCharacterEncoding("UTF-8"); 否则默认以iso-8859-1 ...

  6. oracle_jdbc_insert_into

    package com.ayang.jdbc; import java.sql.Connection; import java.sql.DriverManager; import java.sql.S ...

  7. LINUX 下 NMAP 内网扫描

    #1.扫描内网存活主机 nmap -sP 10.2.24.* |grep for > tmp #2.扫描主机端口 nmap -A -T4 192.168.1.2 #3.扫描主机的所有端口 nma ...

  8. 分布式ID生成方法-趋势有序的全局唯一ID

    一.需求缘起 几乎所有的业务系统,都有生成一个记录标识的需求,例如: (1)消息标识:message-id (2)订单标识:order-id (3)帖子标识:tiezi-id 这个记录标识往往就是数据 ...

  9. Windows下整合apache和Tomcat

    1.前言: 引用:http://www.cnblogs.com/liaokailin/p/3963603.html 引用的博客里面有比较详细的说明,并且结合图片,非常生动: 我这里只做简单的说明和整合 ...

  10. 深入理解Java虚拟机:虚拟机类加载机制

    目录 7.1 概述 7.2 类加载的时机 类的生命周期 5种情况需要"初始化" 7.3 类加载的过程 1.加载 2.验证 3.准备 4.解析 5.初始化 7.4 类加载器 类与类加 ...