Codefroces 762A k-th divisor 数论
题目大意:
给定两个正整数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 数论的更多相关文章
- Codeforces 762A k-th divisor(数论)
题目链接:k-th divisor 求出N的第K大因子,满足N <= 10^15,K <= 10^9 直接暴力…… #include <bits/stdc++.h> using ...
- 牛客练习赛16D K进制 数论(待理解QAQ)
正解:数论 解题报告: 行吧那就让我一点点推出来趴QAQ
- 【codeforces 762A】k-th divisor
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【Codeforces 762A】 k-th divisor
[题目链接] 点击打开链接 [算法] 我们知道,一个数的因子是成对出现的,一半小于等于sqrt(N),一半大于sqrt(N),因此,我们可以从 2..sqrt(N)枚举因子 [代码] #include ...
- 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 ...
- 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 ...
- BZOJ2729:[HNOI2012]排队(组合数学)
Description 某中学有 n 名男同学,m 名女同学和两名老师要排队参加体检.他们排成一条直线,并且任意两名女同学不能相邻,两名老师也不能相邻,那么一共有多少种排法呢?(注意:任意两个人都是不 ...
- 大整数类BIGN的设计与实现 C++高精度模板
首先感谢刘汝佳所著的<算法竞赛入门经典>. 众所周知,C++中储存能力最大的unsigned long long 也是有着一个上限,如果我们想计算非常大的整数时,就不知所措了,所以,我写了 ...
- gym 100735I
Description standard input/outputStatements You are given three numbers. Is there a way to replace v ...
随机推荐
- android中使用百度定位sdk实时的计算移动距离
; //5秒刷新一次 private Handler refreshHandler = new Handler(){ //刷新界面的Handler public void handleMessag ...
- 一个数组nums,其中任意两个值等于给定值target,返回这两个值在nums里的位置
package com.java.tencent; import java.lang.reflect.Array; import java.util.Arrays; import java.util. ...
- python爬虫获取百度图片(没有精华,只为娱乐)
python3.7,爬虫技术,获取百度图片资源,msg为查询内容,cnt为查询的页数,大家快点来爬起来.注:现在只能爬取到百度的小图片,以后有大图片的方法,我会陆续发贴. #!/usr/bin/env ...
- servletResponse 文件下载
package response; import java.io.FileInputStream;import java.io.FileOutputStream;import java.io.IOEx ...
- 去掉activity默认动画效果的方法
非常多手机都会自带一些Activity切换动画,项目中假设我们须要禁用掉系统Activity切换的动画.能够使用例如以下方法: 一.重写Activity的Them中的windowAnimationSt ...
- django数据库同步时报错“Table 'XXX' already exists”
转自:http://blog.csdn.net/huanhuanq1209/article/details/77884014 执行manage.py makemigrations 未提示错误信息, 但 ...
- 允许局域网内其他主机访问本地MySql数据库
mysql的root账户,我在连接时通常用的是localhost或127.0.0.1,公司的测试服务器上的mysql也是localhost所以我想访问无法访问,测试暂停. 解决方法如下: 1,修改表, ...
- 特权级概述(哥子就想知道CPU是如何验证特权级的)GATE+TSS
[0]README text description from orange's implemention of a os . [1]特权级概述 当当前代码段试图访问一个段或者门时,目标段的DPL将会 ...
- yum 安装apache php 使php支持memcached扩展
在公司上新项目的时候,无论生产环境还是测试环境,都会让运维安装php 环境(lamp/lnmp),并让php支持memcached 的扩展.这里搭建php环境其实主要就是搭建apache 和php.m ...
- SQL语句备份和还原数据库(转)
1,使用SQL最简单备份,还原数据库 1 /* 备份 */ 2 backup database Test to disk='D:/Test.bak' 3 /* 还原 */ 4 restore data ...