HDU 5019 Revenge of GCD(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019
that divides the numbers without a remainder.
---Wikipedia
Today, GCD takes revenge on you. You have to figure out the k-th GCD of X and Y.
Each test case only contains three integers X, Y and K.
[Technical Specification]
1. 1 <= T <= 100
2. 1 <= X, Y, K <= 1 000 000 000 000
3
2 3 1
2 3 2
8 16 3
1
-1
2
官方题解:
代码例如以下:
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef __int64 LL;
vector<LL>v;
LL GCD(LL a, LL b)
{
if(b == 0)
return a;
return GCD(b,a%b);
} int main()
{
int t;
LL x, y, k;
scanf("%d",&t);
while(t--)
{
v.clear();
scanf("%I64d%I64d%I64d",&x,&y,&k);
LL tt = GCD(x,y);
// printf("%I64d\n",tt);
for(LL i = 1; i*i <= tt; i++)
{
if(tt%i == 0)
{
v.push_back(i);
if(i*i != tt)//防止放入两个i
v.push_back(tt/i);
}
}
sort(v.begin(), v.end());
if(k > v.size())
printf("-1\n");
else
printf("%I64d\n",v[v.size()-k]);
}
return 0;
}
HDU 5019 Revenge of GCD(数学)的更多相关文章
- 数学--数论--HDU 5019 revenge of GCD
Revenge of GCD Problem Description In mathematics, the greatest common divisor (gcd), also known as ...
- HDU 5019 Revenge of GCD
题解:筛出约数,然后计算即可. #include <cstdio> #include <algorithm> typedef long long LL; LL a1[10000 ...
- HDOJ 5019 Revenge of GCD
Revenge of GCD In mathematics, the greatest common divisor (gcd), also known as the greatest common ...
- hdu 5018 Revenge of GCD
题意: 给你两个数:X和Y .输出它们的第K大公约数.若不存在输出 -1 数据范围: 1 <= X, Y, K <= 1 000 000 000 000 思路: 它俩的公约数一定是gcd ...
- hdu 5869 区间不同GCD个数(树状数组)
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- hdu 5656 CA Loves GCD(n个任选k个的最大公约数和)
CA Loves GCD Accepts: 64 Submissions: 535 Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 2 ...
- hdu 4983 Goffi and GCD(数论)
题目链接:hdu 4983 Goffi and GCD 题目大意:求有多少对元组满足题目中的公式. 解题思路: n = 1或者k=2时:答案为1 k > 2时:答案为0(n≠1) k = 1时: ...
- hdu 5019(第K大公约数)
Revenge of GCD Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 4983 Goffi and GCD(数论)
HDU 4983 Goffi and GCD 思路:数论题.假设k为2和n为1.那么仅仅可能1种.其它的k > 2就是0种,那么事实上仅仅要考虑k = 1的情况了.k = 1的时候,枚举n的因子 ...
随机推荐
- Office2013版的破解之路
追着潮流,我还是更新了我的所有软件,2013版早就下载了,因为一直破解的问题没有装,这次终于找到必成功的办法. 1.准备工作: 下载office2013的官方版即可,官方版里不包含project和vi ...
- 三角剖分求多边形面积的交 HDU3060
//三角剖分求多边形面积的交 HDU3060 #include <iostream> #include <cstdio> #include <cstring> #i ...
- Slideout吐槽
前言: 今天有点事,只尝试做一个侧边栏.SlideOut一个侧边栏,对着github,ReadMe看,并尝试着写了.还不错,关键是当与bootstrap一起时,什么效果都没了, 这是什么情况,明天想再 ...
- cubieboard中使用py-kms与dnsmasq搭建局域网内全自动KMS激活环境
众所周知,KMS激活方式是当前广大网民“试用”windows,office的最广泛的激活方式.几乎可以用于微软的全线产品. 但是在本机使用KMS类的激活工具总是有些不放心,一方面每隔180天都要重新激 ...
- How to Keep Alive SSH Sessions
How to Keep Alive SSH Sessions Many NAT firewalls time out idle sessions after a certain period of t ...
- elang 字符处理
%%% %%% 判断是否是字符串 %%% 从文件中提取中文 %%% %%% %%% %%-------------------------------------------------------- ...
- Failed to read artifact descriptor--maven问题总结(能力工场)
在开发的过程中,作为新手,经常遇到Maven下载依赖的时候,"Failed to read artifact descriptor for xxx:jar"的错误 对于这种非业务相 ...
- MacTerminal快捷键
[MacTerminal快捷键] 在Mac系统中并没有Home.End等键,所以在使用时并不是特别的顺手,但是有几个键位组合可以使Terminal的操作更加灵活方便. 1.将光标移动到行首:ctrl ...
- linux运维工程师
本人是linux运维工程师,对这方面有点心得,现在我说说要掌握哪方面的工具吧说到工具,在行外可以说是技能,在行内我们一般称为工具,就是运维必须要掌握的工具.我就大概列出这几方面,这样入门就基本没问题了 ...
- “IPSec 共享密钥”丢失。
“IPSec 共享密钥”丢失.请验证您的设置并尝试重新连接. 但是这个vpn原来使用时不需要配置 共享的密钥,而且我也没有这个共享的密钥, 搜了下Mac OSX可以修改配置来绕过它. 在/etc/pp ...