Codeforces 762A k-th divisor(数论)
题目链接:k-th divisor
求出N的第K大因子,满足N <= 10^15,K <= 10^9
直接暴力……
#include <bits/stdc++.h> using namespace std; #define rep(i,a,b) for(int i(a); i <= (b); ++i)
#define LL long long LL n, k, h, ans;
int num; int main(){ scanf("%lld%lld", &n, &k);
h = (LL)sqrt(n + 0.5);
if (h * h == n){
rep(i, , h - ) if (n % i == ) num += ;
++num;
}
else{ rep(i, , h) if (n % i == ) num += ; } if (num < k){ puts("-1"); return ; } if (h * h == n){
int cnt = ;
if (k <= num / ){
rep(i, , h) if (n % i == ){
++cnt;
if (cnt == k){
ans = i;
break;
}
}
} else if (k == num / + ){
printf("%lld\n", h);
return ;
} else{
int m = k - num / - ;
int ret = num / - m + ;
rep(i, , h) if (n % i == ){
++cnt;
if (cnt == ret){
ans = n / i;
break;
}
}
}
} else
{
int cnt = ;
if (k <= num / ){
rep(i, , h) if (n % i == ){
++cnt;
if (cnt == k){
ans = i;
break;
}
}
} else{
int m = k - num / , cnt = ;
int ret = num / - m + ;
rep(i, , h) if (n % i == ){
++cnt;
if (cnt == ret){
ans = n / i;
break;
}
}
}
} printf("%lld\n", ans);
return ; }
Codeforces 762A k-th divisor(数论)的更多相关文章
- 【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 ...
- Codefroces 762A k-th divisor 数论
Codeforces 762A 题目大意: 给定两个正整数n,k\((n \le 10^{15},k\leq10^9)\),求n的从小到大的第k个约数,无解输出-1 分析: 我们会自然而然地想到找出n ...
- [CodeForces - 1225D]Power Products 【数论】 【分解质因数】
[CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- Codeforces gym102152 K.Subarrays OR
传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...
- Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...
- Codeforces 837E Vasya's Function - 数论
Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = ...
- Codeforces 837D Round Subset - 动态规划 - 数论
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...
随机推荐
- 从头开始学习数据库及ADO.NET之PostgreSql字段约束——竹子整理
约束数据表列执行的规则.这些是用来防止无效的数据被输入到数据库中..这确保数据库中的数据的准确性和可靠性. 约束可以是列级或表级.仅适用于表级约束被应用到整个表的列级约束.为列定义的数据类型,本身是一 ...
- 洛谷P1540 机器翻译
题目链接:https://www.luogu.org/problemnew/show/P1540
- 继承Thread类使用多线程
java实现多线程有两种方式,一种是继承Thread类,另外一种就是实现Runnable接口. 两种实现方法的优缺点: 使用Thread类实现多线程局限性就是不支持多继承,因为java是不支持类多继承 ...
- python - 接口自动化测试 - GetLog - 日志类封装
# -*- coding:utf-8 -*- ''' @project: ApiAutoTest @author: Jimmy @file: get_logger.py @ide: PyCharm C ...
- Python-S9——Day109-Git及Redis
1.初识Git: 2.Git版本控制之stash和branch: 1.初识Git: 1.1 Git是什么? Git是一个用于帮助用户实现“版本控制”的软件: 1.2 Git安装: GIt官网:http ...
- Django中从本地上传excel文件并将数据存储到数据库
Django中从本地上传excel文件并将数据存储到数据库 一.前端界面 <div class="page-container"> <form action=&q ...
- c++ primer plus 第6版 部分三 9章 - 章
c++ primer plus 第6版 部分三 9章 - 章 第9章 内存模型和名称空间 1.单独编译 ...
- aspx页面直接访问后台方法
在方法上面机上[WebMethod]就可以直接请求该方法了.
- BZOJ 4460 [Jsoi2013]广告计划 ——Bitset 后缀自动机
发现n比较小,直接枚举答案,然后发现连续的一段是确定的,然后我们只需要判断每个位置是否有这个连续的一段就好了 发现起点不同,最后的位置可能会有差距,所以DP一下就好了 然后用0表示未折返,1表示从最下 ...
- vue中echarts 在element-ui的tab 切换时 width 为100px 时的解决方式
最近在项目中遇到了这种情况,需要在tab控件上渲染多个echart图标,然后切换查看时,发现图表的宽度不正确 原因:在页面进行加载时,隐藏的图表找不到对应的div大小,所以默认给了一个大小.所以要做的 ...