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. 利用XStream实现对象XML话

    使用Java原生的序列化的方式来表示一个对象.总结一下这种对象表示方式的优缺点: 1.纯粹的Java环境下这种方式可以很好地工作,因为它是Java自带的,也不需要第三方的Jar包的支持 2.多语言环境 ...

  2. mybatis中各种数据的映射类型

    Mybatis对应的java和数据库的数据类型,最后有图片 Mybatis                                  java                          ...

  3. Java方式 MySQL数据库连接

    JDBC-ODBC : 桥连就是将对JDBC API的调用转换为对另一组数据库连接(即 ODBC) API 的调用 JDBC-ODBC桥连方式驱动类是: sun.jdbc.odbc.JdbcOdbcD ...

  4. MySQL 启动服务和登陆参数

    启动MySQL服务:net start mysql; 停止MySQL服务:net stop mysql; 参数 描述 -D,--database=name 打开指定数据库 --delimiter=na ...

  5. 手机访问PC网站自动跳转到手机网站代码

    方法一: <script type="text/javascript"> try { var urlhash = window.location.hash; if (! ...

  6. mysql——免安装配置

    1.下载 (1)下载地址:https://dev.mysql.com/downloads/mysql/ (2)选择下载 2.配置环境变量 (1)解压目录:D:\mysql-8.0.16-winx64 ...

  7. ACM_数数有多少(第二类Stirling数-递推dp)

    数数有多少 Time Limit: 2000/1000ms (Java/Others) Problem Description: 小财最近新开了一家公司,招了n个员工,但是因为资金问题,办公楼只有m间 ...

  8. ACM_Hailstone HOTPO

    Hailstone HOTPO Time Limit: 2000/1000ms (Java/Others) Problem Description: The hailstone sequence is ...

  9. mysqli 进一步分析

    1. 一.mysql与mysqli的概念相关: 1.mysql与mysqli都是php方面的函数集,与mysql数据库关联不大. 2.在php5版本之前,一般是用php的mysql函数去驱动mysql ...

  10. native2ascii命令详解

    1.native2ascii简介:    native2ascii是sun java sdk提供的一个工具.用来将别的文本类文件(比如*.txt,*.ini,*.properties,*.java等等 ...