Codeforces 762A

题目大意:

给定两个正整数n,k\((n \le 10^{15},k\leq10^9)\),求n的从小到大的第k个约数,无解输出-1

分析:

我们会自然而然地想到找出n的所有的约数,然后取第k个。

我们发现如果这样的话时间复杂度为\(O(\sqrt{n})\),空间复杂度为\(O(lnn)\)

所以我们暴力上就好了

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
template<typename T>inline void read(T &x){
x=0;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=10*x+ch-'0',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline ll cat_max(const ll &a,const ll &b){return a>b ? a:b;}
inline ll cat_min(const ll &a,const ll &b){return a<b ? a:b;}
ll a[2000010],cnt1;
ll b[2000010],cnt2;
int main(){
ll n,k;read(n);read(k);
for(ll i=1;i*i<=n;++i){
if(n % i == 0){
a[++cnt1] = i;
if(i*i != n) b[++cnt2] = n/i;
}
}
if(k > cnt1 + cnt2) puts("-1");
else{
if(k <= cnt1){
printf("%I64d\n",a[k]);
}else{
k -= cnt1;
printf("%I64d\n",b[cnt2-k+1]);
} }
getchar();getchar();
return 0;
}

Codefroces 762A k-th divisor 数论的更多相关文章

  1. Codeforces 762A k-th divisor(数论)

    题目链接:k-th divisor 求出N的第K大因子,满足N <= 10^15,K <= 10^9 直接暴力…… #include <bits/stdc++.h> using ...

  2. 牛客练习赛16D K进制 数论(待理解QAQ)

    正解:数论 解题报告: 行吧那就让我一点点推出来趴QAQ

  3. 【codeforces 762A】k-th divisor

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. 【Codeforces 762A】 k-th divisor

    [题目链接] 点击打开链接 [算法] 我们知道,一个数的因子是成对出现的,一半小于等于sqrt(N),一半大于sqrt(N),因此,我们可以从 2..sqrt(N)枚举因子 [代码] #include ...

  5. UVA 10497 - Sweet Child Makes Trouble 高精度DP

    Children are always sweet but they can sometimes make you feel bitter. In this problem, you will see ...

  6. HDU5568/BestCoder Round #63 (div.2) B.sequence2 dp+高精度

    sequence2 Problem Description Given an integer array bi with a length of n, please tell me how many ...

  7. BZOJ2729:[HNOI2012]排队(组合数学)

    Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不 ...

  8. 大整数类BIGN的设计与实现 C++高精度模板

    首先感谢刘汝佳所著的<算法竞赛入门经典>. 众所周知,C++中储存能力最大的unsigned long long 也是有着一个上限,如果我们想计算非常大的整数时,就不知所措了,所以,我写了 ...

  9. gym 100735I

    Description standard input/outputStatements You are given three numbers. Is there a way to replace v ...

随机推荐

  1. we are experimenting with a new init system and it is fun

    http://0pointer.de/blog/projects/systemd.html Rethinking PID 1 If you are well connected or good at ...

  2. css 使表格随着内容自动适应宽度

    所谓难而不会,会儿不难.这个问题让我纠结了很长时间,一句css解决了,仅仅靠一个属性 td { white-space: nowrap; }

  3. 蓝桥杯OJ PREV-19 九宫重排

    题目描写叙述:   历届试题 九宫重排   时间限制:1.0s   内存限制:256.0MB        问题描写叙述 如以下第一个图的九宫格中,放着 1~8 的数字卡片.另一个格子空着.与空格子相 ...

  4. PHP与js之间的交互

    <?php//在php中药想使用jquery,首先需要导入jquery类库 echo "<script src='".base_url('static')." ...

  5. struts2的 defalut-action-ref 的使用

    这个配置的用法有值得注意的地方,所以才记录下来: 一般default-action-refer配置的action是在浏览器中输入的网址只输入到项目时或输入错误的action时 所进入的action,一 ...

  6. 九度OJ 1160:放苹果 (DFS)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:998 解决:680 题目描述: 把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和 ...

  7. iOS 设置字体样式

    1.iOS设置字体样式   label.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24];   字体名如下: F ...

  8. Tomcat学习笔记【2】--- Tomcat安装、环境变量配置、启动和关闭

    本文主要讲Tomcat的安装和配置. 一 Tomcat安装 1.1 下载 下载地址:http://tomcat.apache.org/ 1.2 安装 Tomcat是不需要安装的,解压压缩包即可. 在安 ...

  9. python连接redis并插入url

    #!/usr/bin/env python # -*- coding:utf8 -*- import redis ''' 这种连接是连接一次就断了,耗资源.端口默认6379,就不用写 r = redi ...

  10. Java中的内存泄漏

    [转]介绍Java中的内存泄漏 1. 什么是内存泄漏? 内存泄漏的定义:对象已经没有被应用程序使用,但是垃圾回收器没办法移除它们,因为还在被引用着. 要想理解这个定义,我们需要先了解一下对象在内存中的 ...