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.

solution

原本想了个分解质因数后递推,但发现空间不够

其实可以用时间换空间,暴力嘛

随便做一做就行了

#include <math.h>
#include <vector>
#include <stdio.h>
#define L long long
char B[],*p=B,pb[];
inline void Rin(register L &x){
x=;
while(*p<''||*p>'')p++;
while(*p>=''&&*p<='')
x=x*10LL+*p++-'';
}
inline void Mo(register L x){
register int top=;
while(x)pb[++top]=(x%10LL)+'',x/=10LL;
while(top)putchar(pb[top--]);
putchar('\n');
}
L n,K,s,l1,l2;
std::vector<L>p1,p2;
int main(){
fread(B,,,stdin);
Rin(n),Rin(K);
L s=sqrt(n);
for(register L i=;i<s;i++)
if(n%i==0LL){
p1.push_back(i);
p2.push_back(n/i);
}
if(s*s==n)
p1.push_back(s);
else
if(n%s==){
p1.push_back(s);
p2.push_back(n/s);
}
l1=p1.size(),l2=p2.size();
if(l1+l2<K)
puts("-1");
else{
if(K<=l1)
Mo(p1[K-]);
else
Mo(p2[l2-K+l1]);
}
return ;
}

Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)的更多相关文章

  1. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) E. Pencils and Boxes 题目连接: http://code ...

  3. Codeforces Educational Codeforces Round 15 E - Analysis of Pathes in Functional Graph

    E. Analysis of Pathes in Functional Graph time limit per test 2 seconds memory limit per test 512 me ...

  4. Codeforces Educational Codeforces Round 15 C. Cellular Network

    C. Cellular Network time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  5. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  6. codeforces Educational Codeforces Round 16-E(DP)

    题目链接:http://codeforces.com/contest/710/problem/E 题意:开始文本为空,可以选择话费时间x输入或删除一个字符,也可以选择复制并粘贴一串字符(即长度变为两倍 ...

  7. Codeforces Educational Codeforces Round 15 D. Road to Post Office

    D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...

  8. Codeforces Educational Codeforces Round 5 E. Sum of Remainders 数学

    E. Sum of Remainders 题目连接: http://www.codeforces.com/contest/616/problem/E Description The only line ...

  9. Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法

    D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...

随机推荐

  1. 简述Python中的break和continue的区别

    众所周知在Python中,break是结束整个循环体,而continue则是结束本次循环再继续循环. 但是作为一个新手的你,还是不明白它们的区别,这里用一个生动的例子说明它们的区别,如下: 1.con ...

  2. 一句powershell调用mimikatz抓密码

    mimikatz神器大家都知道吧,可以抓取系统内的明文密码,但是平时我们测试的时候需要把mimikatz的几个文件上传到目标系统上面,然后再手工执行几个命令才能搞定,今天无意访问一个大神的博客,发现其 ...

  3. bzoj 1741: [Usaco2005 nov]Asteroids 穿越小行星群【最大点覆盖】

    二分图最大点覆盖模型,因为对于一个点(x,y)显然只要选x或者y就好了,于是连边,跑最大匹配=最大点覆盖(不会证) #include<iostream> #include<cstdi ...

  4. bzoj 1619: [Usaco2008 Nov]Guarding the Farm 保卫牧场【bfs】

    不是严格小于是小于等于啊!!!!!不是严格小于是小于等于啊!!!!!不是严格小于是小于等于啊!!!!! 是我看不懂人话还是翻译不说人话= = 把所有格子按值排个序,bfs扩展打标记即可 #includ ...

  5. bzoj 1715: [Usaco2006 Dec]Wormholes 虫洞【spfa判负环】

    tag是假的,用了及其诡异的方法判负环 正权无向边和负权有向边的图 #include<iostream> #include<cstdio> #include<cstrin ...

  6. poj2096Collecting Bugs(概率期望dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 6400   Accepted: 3128 ...

  7. 添加tomcat开机启动服务时报错:Neither the JAVA_HOME nor the JRE_HOME enviromment variable is defined

    首先,参考的 https://blog.csdn.net/wabil/article/details/78818249 的方式添加 tomcat 开机启动,这种方式不需要添加 setenv.sh 文件 ...

  8. Linux命令(007) -- systemctl

    systemctl命令是系统服务管理指令,它实际上是将service和chkconfig两个命令组合到一起. 任务 旧指令 新指令 使某服务自动启动 chkconfig --level 3 httpd ...

  9. [转]从数据到代码——基于T4的代码生成方式

    本文转自:http://www.cnblogs.com/artech/archive/2010/10/23/1859529.html 在之前写一篇文章<从数据到代码>(上篇.下篇)中,我通 ...

  10. elastic-job 的简单使用

    说明:这个是使用2.1.5版本 elastic-job是当当开源的的的定时任务,使用也是很简单的,可以解决数据量的大的时候可以分片执行,多应用节点部署时候不会重复执行. 是通过zookeeper作为控 ...