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. 1.2 Use Cases中 Commit Log官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Commit Log 提交日志 Kafka can serve as a kind ...

  2. 基于ContentObserver来动态取消或加入屏幕超时任务

    前面也说了.ContentObserver能够来监控数据库里某一项数据的变化,当然也能够同一时候监控多个数据项的变化. 笔者在项目中须要改动到屏幕超时的需求,比方在车载业务中,倒车事件发生的时候,是不 ...

  3. Fiddler--功能简介

    Fiddler的基本介绍 Fiddler的官方网站:  www.fiddler2.com Fiddler官方网站提供了大量的帮助文档和视频教程, 这是学习Fiddler的最好资料. Fiddler是最 ...

  4. Openstack nova(二)——架构(一)

    架构源自需求 需求分析 软件架构大部分都来自于需求.能够说.有什么样的需求,就会有什么样的架构, 尽管不同一时候期,不同的人来实现,可能不全然一样.可是整体来说, 架构不会相差太远. 如今假设假设须要 ...

  5. java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: student is not mapped

    Spring 5.0 +Jpa,使用@Query实现 自定义查询报错: java.lang.IllegalArgumentException: org.hibernate.hql.internal.a ...

  6. JavaScript中双叹号“!!”作用

    1.JavaScript的逻辑非(!)操作符的作用 (逻辑非) 如果操作数能够转换为true则返回false:否则返回true. 2.!!的作用 !!一般用来将后面的表达式强制转换为布尔类型的数据(b ...

  7. POSIX 多线程编程及理解

    最近开发基于ZYNQ的嵌入式linux程序,涉及到多线程使用,将一些内容整理如下: POSIX多线程编程最为基础和重要的可以分为两部分: 线程操作-Thread Management 线程同步-Syn ...

  8. centos中的配置文件 分类: B3_LINUX 2015-04-03 22:21 184人阅读 评论(0) 收藏

    /etc/profile:此文件为系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.并从/etc/profile.d目录的配置文件中搜集shell的设置. /etc/bashrc:为每一个 ...

  9. stm32四种输入

    1.          上拉输入(GPIO_Mode_IPU)   上拉输入就是信号进入芯片后加了一个上拉电阻,再经过施密特触发器转换成0.1信号,读取此时的引脚电平为高电平:   2.       ...

  10. go 字符串 数字 整型 浮点 转换

    import "strconv" //先导入strconv包 // string到int int, err := strconv.Atoi(string) // string到in ...