题目链接: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(数论)的更多相关文章

  1. 【codeforces 762A】k-th divisor

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  2. 【Codeforces 762A】 k-th divisor

    [题目链接] 点击打开链接 [算法] 我们知道,一个数的因子是成对出现的,一半小于等于sqrt(N),一半大于sqrt(N),因此,我们可以从 2..sqrt(N)枚举因子 [代码] #include ...

  3. Codefroces 762A k-th divisor 数论

    Codeforces 762A 题目大意: 给定两个正整数n,k\((n \le 10^{15},k\leq10^9)\),求n的从小到大的第k个约数,无解输出-1 分析: 我们会自然而然地想到找出n ...

  4. [CodeForces - 1225D]Power Products 【数论】 【分解质因数】

    [CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...

  5. Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论

    Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...

  6. Codeforces gym102152 K.Subarrays OR

    传送:http://codeforces.com/gym/102152/problem/K 题意:给定$n(n\le10^5)$个数$a_i(a_i\le10^9)$,对于任一个子数组中的数进行或操作 ...

  7. Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法

    Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...

  8. 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) = ...

  9. 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 ...

随机推荐

  1. Tricky Sum

    In this problem you are to calculate the sum of all integers from 1 to n, but you should take all po ...

  2. Spring表达式语言:SpEL

    1.Spring表达式语言(简称:SpEL):是一个支持运行时查询和操作对象图的强大的表达式语言. 2.语法类似于EL:SpEL使用#{...}作为定界符,所有在大括号内的字符都被认为是SpEL. 3 ...

  3. luogu2093 [国家集训队]JZPFAR

    题面不符?-- #include <algorithm> #include <iostream> #include <cstdio> using namespace ...

  4. 谋哥:《App自推广》连载2直立人行走迁徙

    [谋哥每天一干货,第六十九篇] 前篇说到声音在远古时代,是一个神奇的东西,它能够很快地把信息传播到其他地方,突破了短距离.然而能人的后代直立人学会了直立行走,他们开始走出非洲,到达遥远的中东.中国,还 ...

  5. 谋哥:App开发者的苦逼不值得怜悯!

    [谋哥每天一干货,第四十篇]        为什么取这个标题呢?因为昨天一些本来“支持”谋哥的人看到谋哥搞收费VIP群,觉得谋哥赚苦逼开发者的钱很不道德,且说谋哥我写的东西都不切实际,全部是一些思想性 ...

  6. Lucene.Net 精品教程

    http://www.cnblogs.com/piziyimao/archive/2013/01/31/2887072.html

  7. Webapp和后端交互检查测试

    除了功能,我们可以使用下面方法,查看交互过程,页面不能发现的问题: 什么是json 什么是json,json是什么,json如何使用 JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能 ...

  8. Visual C++网络五子棋游戏源代码

    说明:网络对战版的五子棋,VC++游戏源码,带音乐,可设置网络最终网络下棋,通过源代码你将了解到设置菜单状态.服务器端口申请.客户机申请连接.发送数据.游戏编写.监听和使用套接字.主菜单对象定义等基础 ...

  9. docker端口的映射顺序

    sudo docker run -d -p 8080:80 --name static_web jamtur01/static_web nginx -g "dameon off;" ...

  10. PAT1017

    本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数.你需要输出商数Q和余数R,使得A = B * Q + R成立. 输入格式: 输入在1行中依次给出A和B,中间以1空格分隔. 输出格 ...