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 ...
随机推荐
- 水题:HDU-1088-Write a simple HTML Browser(模拟题)
解题心得: 1.仔细读题,细心细心...... 2.题的几个要求:超过八十个字符换一行,<br>换行,<hr>打印一个分割线,最后打印一个新的空行.主要是输出要求比较多. 3. ...
- Codeforces 35E Parade 扫描线
题意: 给出\(n\)个底边在\(x\)轴上的矩形,求外面的轮廓线顶点. 分析: 将每个矩形拆成两个事件:\(\\\{ l, y, + \\\}\)和\(\\\{ r, y, - \\\}\)分别表示 ...
- UVa 1649 Binomial coefficients 数学
题意: \(C(n, k) = m(2 \leq m \leq 10^{15})\),给出\(m\)求所有可能的\(n\)和\(k\). 分析: 设\(minK = min(k, n - k)\),容 ...
- 数据库路由中间件MyCat - 使用篇(1)
此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 基本概念 直接介绍概念太枯燥了,还是拿个和背景篇相似的例子介绍 业务场景:客户完成下单,快递员接受并更新运单 ...
- Singleton模式类 【微软面试100题 第七十二题】
题目要求: 实现C++单例模式,即只能生成一个实例的类. 题目分析: 1.一般情况:用构造函数私有化和静态函数实现. 2.如果考虑内存泄露:用智能指针+一般情况方法. 3.如果考虑线程安全:加锁. 代 ...
- 【Jump Game】cpp
题目: Given an array of non-negative integers, you are initially positioned at the first index of the ...
- [oldboy-django][5python基础][内置函数]zip
python3中,把两个或两个以上的迭代器封装成生成器,在循环遍历生成器中,不断产生元组. 如果提供的迭代器长度不对等,生成器的长度为最短迭代器的长度. # coding= utf-8 # zip 多 ...
- [python][django学习篇][11]后台admin用户登录博客,添加文章---这一章和博客首页设计没有关系
1 如果没有创建超级管理员账号,先要创建python manage.py createsuperuser 2 在admin后台注册模型(如果没有这一步,登录http://127.0.0.1:8000/ ...
- Gym100623A Access Control Lists
Gym 100623A Access Control Lists 这个题很sb啊,就是去设置个交换机 我们可以给一个IP进行设置,也可以对一个网段就行设置,但是IP是优于网段的,比如样例的第一个 网段 ...
- quagga源码学习--BGP协议创建对等体
现有的路由协议都是通过分布式协议逐个配置协商运行的,协议协议,一个就不需要协议咯,至少2个才能够协议着做事情嘛,不过呢,这样就出现网元过多配置困难的问题,对网管软件要求也越来越高, SDN或许可能改变 ...