time limit per test2 seconds

memory limit per test256 megabytes

inputstandard input

outputstandard 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.

【题目链接】:http://codeforces.com/contest/762/problem/A

【题解】



可以只枚举sqrt(n);

因子是成对出现的;

所以i是n的因子

n/i也是n的因子;

注意i*i=n的情况就好;

对于小于sqrt(n)的放在v里面,大于sqrt(n)的放在vv里面;

v是升序的,vv是降序的;因为n/i=x (i< sqrt(n),则x>sqrt(n))

然后根据k和两个v的size的关系.控制输出就好;

(一个数的因子不会那么多的,就算1e15,也没超过1000个因子)



【完整代码】

#include <bits/stdc++.h>
#define LL long long
#define pb push_back
using namespace std; LL n,k,cnt = 0,temp;
vector <LL> v,vv; int main()
{
//freopen("F:\\rush.txt","r",stdin);
cin >> n >> k;
LL t = sqrt(n);
for (LL i = 1;i <= t-1;i++)
if (n%i==0)
{
v.pb(i);
vv.pb(n/i);
}
if (t*t==n)
v.pb(t);
else
if (n%t==0)
{
v.pb(t);
vv.pb(n/t);
}
int len1 = v.size(),len2 = vv.size();
int cnt = len1+len2;
if (cnt<k)
puts("-1");
else
{
if (k<=len1)
cout << v[k-1] << endl;
else
cout << vv[len2-1-(k-len1)+1]<<endl;
}
return 0;
}

【codeforces 762A】k-th divisor的更多相关文章

  1. 【Codeforces 762A】 k-th divisor

    [题目链接] 点击打开链接 [算法] 我们知道,一个数的因子是成对出现的,一半小于等于sqrt(N),一半大于sqrt(N),因此,我们可以从 2..sqrt(N)枚举因子 [代码] #include ...

  2. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  3. 【codeforces 757B】 Bash's Big Day

    time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...

  4. 【codeforces 755D】PolandBall and Polygon

    time limit per test4 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

  8. 【codeforces 797E】Array Queries

    [题目链接]:http://codeforces.com/problemset/problem/797/E [题意] 给你一个n个元素的数组; 每个元素都在1..n之间; 然后给你q个询问; 每个询问 ...

  9. 【codeforces 801A】Vicious Keyboard

    [题目链接]:http://codeforces.com/contest/801/problem/A [题意] 一个字符串只由VK组成; 让你修改一个字符; 使得剩下的字符串里面子串VK的个数最大; ...

随机推荐

  1. 第6章4节《MonkeyRunner源代码剖析》Monkey原理分析-事件源-事件源概览-翻译命令字串

    在第2节中我们看到了MonkeySourceNetwork是怎样从Socket中获取MonkeyRunner发送过来的命令字串的,可是最后怎样将它翻译成事件的代码我们还没有进行分析,由于在那之前我们还 ...

  2. php函数symlink详解

    php函数symlink详解 建立符号链接 (symbolic link),类似于Windows里头常用的.lnk快捷方式 symlink语法: int symlink(string target, ...

  3. Leetcode-求两数之和

    题目: 给定一个整数数组 nums 和一个目标值 target,请你在该数组中找出和为目标值的那 两个 整数,并返回他们的数组下标. 你可以假设每种输入只会对应一个答案.但是,你不能重复利用这个数组中 ...

  4. jfreechart,pdf生成组件iText,jasper report报表组件及POI操作excel等在企业软件开发中常遇到的第三方应用

    熟悉WEB Service ,Ajax,DWR,JQuery,iBatis等技术,熟练TOMCAT,IIS,JBoss,WebLogic等服务器 图表组件JFreeChart PDF组件-iText的 ...

  5. DataTable +chart控件

    //这是仿你的DataTable //-----开始--------- DataTable dataTable1 = new System.Data.DataTable(); dataTable1.C ...

  6. Oracle学习总结(9)—— Oracle 常用的基本操作

    创建用户,相当于在sqlServer中创建一个数据库  create user 用户名 identified by 密码  修改用户密码  alter user 用户名 identified by 新 ...

  7. android String 类型转换成UTF-8格式

    在android开发中,有时候会遇到汉字乱码的问题,在这个时候,吧String串加一个编码格式转换,转换成UTF-8的格式就可以了 public static String toUtf8(String ...

  8. DC中为什么要用Uniquify?

    转自:http://blog.sina.com.cn/s/blog_68c493870101exl7.html 为了在layout中进行时钟树的综合,网表在DC中必须被uniquified.所谓uni ...

  9. 1、初识python

    1.linux下运行python脚本时,在第一行通过“#!/usr/bin/env python”指定python h.py <=> ./h.py 具有相同的效果 (h.py需要有执行权限 ...

  10. jquery实现ajax提交form表单的方法总结(转)

    方法一: 复制代码 代码如下: function AddHandlingFeeToRefund() {            var AjaxURL= "../OrderManagement ...