Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)
2024-09-30 21:46:04
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 ;
}
最新文章
- Jmeter发送soap请求
- Unity3D 之 iTween 相关
- Visual Studio 技能GET
- LED应用照明产品常识关键点
- Windows 8.1 新增控件之 AppBar
- 事件监听addEventListener()和removeEventListener() ---------1
- hbase 停止regionserver
- Vue.js学习 Item12 – 内部响应式原理探究
- 20. Screen
- R与数据分析旧笔记(十)非线性模型
- POJ 2914 Minimum Cut 最小割图论
- Chrome 里的请求报错 ";CAUTION: Provisional headers are shown"; 是什么意思?
- linux下初始化mysql时报错
- SSRF漏洞浅析
- mysql入门学习笔记
- python多线程-共享全局变量
- HDU 1175 连连看 (DFS+剪枝)
- DotNetty项目基本了解和介绍
- js检查字符串的包含关系
- sqlite 数据库错误 The database disk image is malformed database disk image
热门文章
- bzoj2440 [中山市选2011]完全平方数——莫比乌斯+容斥
- oracle 统计/分析函数
- EJB是什么?EJB的概念分析与理解(copy)
- 栗染-git命令搭建简单的个人的网页
- object-c中实现特定一个或者多个页面横竖屏,其他界面保持竖屏显示。
- 二分搜索 Codeforces Round #218 (Div. 2) C. Hamburgers
- iPhone4到iPhone6的设计、制造工艺历程浅析
- HTML空格占位
- Laravel5.1学习笔记21 EloquentORM 集合
- CF848A From Y to Y