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 ...
随机推荐
- [USACO]奶牛博览会(DP)
Description 奶牛想证明他们是聪明而风趣的.为此,贝西筹备了一个奶牛博览会,她已经对N头奶牛进行了面试,确定了每头奶牛的智商和情商. 贝西有权选择让哪些奶牛参加展览.由于负的智商或情商会造成 ...
- ZOJ 3231 Apple Transportation 树DP
一.前言 红书上面推荐的题目,在138页,提到了关键部分的题解,但是实际上他没提到的还有若干不太好实现的地方.尤其是在这道题是大家都拿网络流玩弄的大背景下,这个代码打不出来就相当的揪心了..最后在牛客 ...
- Tomcat之web.xml中的<url-pattern>标签
关于web.xml配置中的<url-pattern> 标签<url-pattern> <url-pattern>是我们用Servlet做Web项目时需要经常配置的标 ...
- Nodejs-文件系统操作
1.相关模块 2.同步调用和异步调用 注意:他们的捕获异常的方式不一样 写入文件 语法 以下为异步模式下写入文件的语法格式: fs.writeFile(filename, data[, options ...
- day21&22&23:线程、进程、协程
1.程序工作原理 进程的限制:每一个时刻只能有一个线程来工作.多进程的优点:同时利用多个cpu,能够同时进行多个操作.缺点:对内存消耗比较高当进程数多于cpu数量的时候会导致不能被调用,进程不是越多越 ...
- loj2046 「CQOI2016」路由表
大傻逼trie树,更傻逼的是我这都没独立想出来,以后要少看题解,多多思考 #include <algorithm> #include <iostream> #include & ...
- IOS开发---菜鸟学习之路--(二十)-二维码扫描功能的实现
本章将讲解如何实现二维码扫描的功能 首先在github上下载ZBar SDK地址https://github.com/bmorton/ZBarSDK 然后将如下的相关类库添加进去 AVFoundati ...
- js 遍历对象属性(for in、Object.keys、Object.getOwnProperty) 以及高效地输出 js 数组
js中几种遍历对象的方法,包括for in.Object.keys.Object.getOwnProperty,它们在使用场景方面各有不同. for in 主要用于遍历对象的可枚举属性,包括自有属性. ...
- Adaboost和GBDT的区别以及xgboost和GBDT的区别
Adaboost和GBDT的区别以及xgboost和GBDT的区别 以下内容转自 https://blog.csdn.net/chengfulukou/article/details/76906710 ...
- 处理python字符串中的中文字符
# -*- coding:utf-8 -*- import sys,os txta = open('a.txt','r') str = '' for line in txta: str += line ...