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. Python大法之从火车余票查询到打造抢Supreme神器

    本文作者:i春秋作家——阿甫哥哥 系列文章专辑:https://bbs.ichunqiu.com/forum.php?mod=collection&action=view&ctid=9 ...

  2. linux 服务器性能监控(一)

    这篇文章主要介绍一些常用的linux服务器性能监控命令,包括命令的常用参数.指标的含义以及一些交互操作. 几个问题 命令本身并不复杂,关键是你对操作系统基础知识的掌握和理解,先来看看下面几个问题: C ...

  3. UIKit: Apps for Every Size and Shape

    safeArea 即可以正常显示内容的部分.   可以通过 additionalSafeAreaInsets 来调整 safeArea 的大小.  经过调整,范围如下: self.additio ...

  4. day 70 crm(7):stark组件调用,以及权限分配

    前情提要: 复习:  1: orm !!!!! 2: session 3: django 4:  前端在复习 5:  复习中间件 学习的stark 的组件调用,以及权限的应用 一:权限的概念,  1: ...

  5. Oracle 数据库维护管理之--dbms_lock

    1.查询相关的v$视图,但是提示表或视图不存在解决办法     原因是使用的用户没有相关的查询权限导致 解决办法: grant select  any dictionary to 用户;    --这 ...

  6. mysql 执行 sql 语句提示Parameter '@XXX' must be defined

    执行 sql 语句 MySqlException: Parameter '@maxNo' must be defined. 执行 sql 中含有自定义变量 @maxNo,抛出异常 解决方法: 连接字符 ...

  7. 使用TopShelf做windows服务

    class Program { static void Main(string[] args) { HostFactory.Run(x => { x.RunAsLocalSystem(); x. ...

  8. matplotlib基本使用(矩形图、饼图、热力图、3D图)

    使用matplotlib画简单的图形: #-*- coding:utf-8 -*- from numpy.random import randn import matplotlib.pyplot as ...

  9. javascript字符串拼接

    var c='../Project/SelectPerson.aspx?personList='+'"'+personListValue+'"' X('Window2').x_sh ...

  10. ILSpy工具使用

    Reflector是.NET开发中必备的反编译工具.即使没有用在反编译领域,也常常用它来检查程序集的命名规范,命名空间是否合理,组织类型的方法是否需要改善.举例说明,它有一个可以查看程序集完整名称的功 ...