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 ...
随机推荐
- 动态规划:完全背包问题-HDU1114-Piggy-Bank
解题心得: 1.这是一个完全背包问题的变形,题目要求是求在规定的重量下求价值最小,所以需要将d[0]=0关键的初始化 2.当不可能出现最小的价值时,d的状态并没有被改变,说明并没有放进去一个硬币. 题 ...
- PAT basic 1086
1086 就不告诉你 (15 分) 做作业的时候,邻座的小盆友问你:“五乘以七等于多少?”你应该不失礼貌地围笑着告诉他:“五十三.”本题就要求你,对任何一对给定的正整数,倒着输出它们的乘积. 输入格式 ...
- Android广告页循环播放
摘要:项目要求做一个广告页,实现几秒更换一次广告页,下方还有指示第几张广告页,同样也支持手动左滑或右滑. 1.准备好粘贴5个有关广告页的类. ①BaseViewPager==>自定义高度的Vie ...
- Django 四——ModelForm用法
内容概要: 1.新增数据库表中数据 2.更新数据库表中数据 Django的ModelForm Django中内置了Form和Model两个类,有时候页面的表单form类与Model类是一一对应,因此分 ...
- VC下如何调用控制台命令以及其他可执行文件
开始的时候想写一个基于MFC的Wifi开关控制程序,可是不知道VC中如何调用控制台命令,经过网上的学习,发现其实挺挺简单也挺好用.于是制作了一个简单的基于MFC个人助理小软件,可以点击按钮实现Wifi ...
- [python][django学习篇[13]增加markdown_1
1 进入虚拟环境,安装markdwon python install markdown 2 修改视图函数detail def detail(request, pk): # get_object_or ...
- [转]Ubuntu下添加开机启动脚本
作者: 王恒 发表于 2012年 11月 5日 1.方法一,编辑rc.loacl脚本 Ubuntu开机之后会执行/etc/rc.local文件中的脚本, 所以我们可以直接在/etc/rc.local中 ...
- BZOJ 1050: [HAOI2006]旅行comf(枚举+并查集)
[HAOI2006]旅行comf Description 给你一个无向图,N(N<=500)个顶点, M(M<=5000)条边,每条边有一个权值Vi(Vi<30000).给你两个顶点 ...
- hihoCoder #1867 GCD
在集合 $[n]$ 上使用容斥原理. 固定 $i$,考虑有多少个 $j \in [n]$ 满足 $\gcd(i, j) = \gcd(a_i, a_j) = 1$,将此数目记作 $f_i$.暂时不考虑 ...
- /bin , /sbin , /usr/sbin , /usr/local/sbin 的区别
usr 是 UNIX Software Resource 的缩写,也就是 Unix操作系统软件资源 所放置的目录. 一 /bin:Essential user command binaries(for ...