CodeForces762A
A. k-th divisor
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的更多相关文章
- 在ubuntu下编写python
一般情况下,ubuntu已经安装了python,打开终端,直接输入python,即可进行python编写. 默认为python2 如果想写python3,在终端输入python3即可. 如果需要执行大 ...
随机推荐
- ElasticSearch的概念解析
ElasticSearch是面向文档的,它不仅仅可以存储整个对象或则文档(document),还会索引(index)每个文档的内容使它可以被快速的检索.ElasticSearch和关系型数据库的对比如 ...
- 原来css也可以计算-calc()使用
在浏览其他人的源代码时,看到了一个陌生的属性:width:calc(100% - 10px -10px); 出于好奇心,百度了一下,看到了以下这篇文章,http://www.w3cplus.com/c ...
- 如何取消mysql授权并删除用户
如何查看授权的所有用户SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;撤销已经赋 ...
- vertical-tical
通常我们需要垂直对齐并排的元素. CSS提供了一些可实现的方法:有时我用浮动float来解决,有时用position: absolute来解决,有时甚至是“肮脏”地手动添加的margin或paddin ...
- [BZOJ2758] [SCOI2012]Blinker的噩梦 扫描线+set
题目大意:有n个圆或凸多边形,这些图形不会相交,每当走入或走出一个图形时需要异或上一个代价,有m组操作: 询问操作,每次询问从一个点走到另一个点时,需要的代价(初始代价为0) 修改操作,每次修改一个图 ...
- Backing Up and Restoring HBase Data
There are two strategies for backing up HBase:1> Backing it up with a full cluster shutdown2> ...
- 安装freepbx后创建sip分机
在前面的文章阿里云使用镜像安装freepbx里面我们已经使用镜像文件安装好了freepbx,接下来开始是开始创建SIP分机,实现可以拨打电话. 首先我们输入我们的IP可以直接访问到freepbx的界面 ...
- Git 代码管理命令
1) 远程仓库相关命令检出仓库:$ git clone git://github.com/jquery/jquery.git查看远程仓库:$ git remote -v添加远程仓库:$ git rem ...
- Spring Boot 使用Redis
转载自:http://www.cnblogs.com/ityouknow/p/5748830.html Redis支持更丰富的数据结构,例如hashes, lists, sets等,同时支持数据持久化 ...
- java面试③Web部分
2.2.1 讲一下http get和post请求的区别 get和post请求都是http的请求方式,用户通过不同的http请求方式完成对资源(url)的不同操作,具体点来讲get一般用于获取/查询资源 ...