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. Angular 一些问题(跨域,后台接收不到参数)

    1,跨域:跟前端没多大关系的,后台没设置头而已.这时候如果你们后端太菜你可以叫他加上每种语言 都不同,但是里面的呢荣是一样的.具体跨域可以跳转这里http://www.cnblogs.com/dojo ...

  2. JavaScript 作用域链图具体解释

    <script type="text/javascript"> /** * 作用域链: */ var a = "a"; function hao94 ...

  3. ReactNative Navigator

    https://facebook.github.io/react-native/docs/navigator.html Navigator实现了页面之间的跳转. Demo描述:打开即进入“课程”页面, ...

  4. erlang处理mongodb日期时间格式data类型(原)

    在项目中,mongo中要创建日期类型,根据这个日期类型进而对mongo设置过期时间expire,加上对应的index索引自动删除. 而mongo中的日期类型,使用ISO格式,例如:ISODate(&q ...

  5. 一些编译php时的configure 参数

    一些编译php时的configure 参数 ./configure –prefix=/usr/local/php php 安装目录 –with-apxs2=/usr/local/apache/bin/ ...

  6. android WebView详细使用方法(转)

    1.最全面的Android Webview详解 2.最全面总结 Android WebView与 JS 的交互方式 3.你不知道的 Android WebView 使用漏洞 如果想保证登录状态,就插入 ...

  7. 新装上线 年度精品 XP,32/64位Win7,32/64位Win10系统【电脑城版】

    随着Windows 10Build 10074 Insider Preview版发布,有理由相信,Win10离最终RTM阶段已经不远了.看来稍早前传闻的合作伙伴透露微软将在7月底正式发布Win10的消 ...

  8. LeetCode(100)题解--Same Tree

    https://leetcode.com/problems/same-tree/ 题目: Given two binary trees, write a function to check if th ...

  9. Android中RelativeLayout各个属性及其含义

    android:layout_above="@id/xxx"  --将控件置于给定ID控件之上android:layout_below="@id/xxx"  - ...

  10. (转)ConcurrentModificationException异常原因和解决方法

    原文地址: http://www.cnblogs.com/dolphin0520/p/3933551.html 一.ConcurrentModificationException异常出现的原因 先看下 ...