hdu 5019(第K大公约数)
Revenge of GCD
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2140    Accepted Submission(s): 596
mathematics, the greatest common divisor (gcd), also known as the
greatest common factor (gcf), highest common factor (hcf), or greatest
common measure (gcm), of two or more integers (when at least one of them
is not zero), is the largest positive integer 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
2 3 1
2 3 2
8 16 3
-1
2
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
#include<queue>
#include<iostream>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b){
return b==?a:gcd(b,a%b);
}
LL p[];
LL cmp(LL a,LL b){
return a>b;
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
LL a,b,k;
scanf("%lld%lld%lld",&a,&b,&k);
LL d = gcd(a,b);
int id = ;
for(LL i=;i*i<=d;i++){ ///筛选出所有因子
if(d%i==){
if(i*i==d) p[id++]=i;
else{
p[id++]=i;
p[id++]=d/i;
}
}
}
if(id<k){
printf("-1\n");
}
else{
sort(p,p+id,cmp);
printf("%lld\n",p[k-]);
}
}
return ;
}
hdu 5019(第K大公约数)的更多相关文章
- __gcd-最大公约数
		__gcd-最大公约数 最大公约数(greatest common divisor,简写为gcd:或highest common factor,简写为hcf) __gcd(x,y)是algorithm ... 
- hdu 4542 打表+含k个约数最小数
		http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求 ... 
- BestCoder10 1002 Revenge of GCD(hdu 5019)  解题报告
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 题目意思:给出 X 和 Y,求出 第 K 个 X 和 Y 的最大公约数. 例如8 16,它们的公 ... 
- HDU 5019 Revenge of GCD(数学)
		题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest ... 
- hdu 5019
		http://acm.hdu.edu.cn/showproblem.php?pid=5019 给出X 和Y,求出第K 大的 X 和Y 的公约数. 暴力求出所有公约数 #include <cstd ... 
- hdu 2639 第k大01背包
		求每个状态里的k优解,然后合并 /* HDU 2639 求01背包的第k大解. 合并两个有序序列 */ #include<stdio.h> #include<iostream> ... 
- HDU 5019 Revenge of GCD
		题解:筛出约数,然后计算即可. #include <cstdio> #include <algorithm> typedef long long LL; LL a1[10000 ... 
- HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)
		6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ... 
- HDU - The number of divisors(约数) about Humble Numbers
		Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The sequence ... 
随机推荐
- cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
			参考 http://blog.csdn.net/mazicwong/article/details/54946952 1.到https://curl.haxx.se/ca/cacert.pem复制下 ... 
- laravel中redis各方法的使用
			在laravel中使用redis自带方法的时候会发现许多原生的方法都不存在了,laravel对其进行了重新的封装但是在文档中并没有找到相关的资料最后在 \vendor\predis\predis\sr ... 
- leetcode-13-basic-binaryTree
			101. Symmetric Tree 解题思路: 递归的方法如下.分几种情况考虑,如果左子树和右子树都是空,那么返回true:如果不同时为空,返回false:如果都不为空,则 判断其值是否相等,不相 ... 
- dict 字典的常用操作
			#dict 字典的常用操作: id_db.get() #获取 id_db.update() #更新(覆盖)字典 id_db.values() #打印字典里所有的values id_db.keys() ... 
- CodeForces 500E New Year Domino
			题意: 从左到右排列着\(n\)个多米诺骨牌,它们分别站在\(x\)轴上的位置\(p_i\)上且高度为\(l_i\). 当第\(i\)个多米诺骨牌向右倒下时,如果\(p_i < p_j \leq ... 
- CodeForces Round #320 Div2
			A. Raising Bacteria 计算一下x的bitcount就是答案. #include <iostream> #include <cstdio> #include & ... 
- luogu1972 [SDOI2009]HH的项链
			莫队裸题还不带修改 #include <algorithm> #include <iostream> #include <cstdio> #include < ... 
- 计算n的阶乘(n!)末尾0的个数
			题目: 给定一个正整数n,请计算n的阶乘n!末尾所含有“0”的个数. 举例: 5!=120,其末尾所含有的“0”的个数为1: 10!= 3628800,其末尾所含有的“0”的个数为2: 20!= 24 ... 
- 大数据学习——scala集合练习
			package com /** * Created by ZX on 2016/4/5. */ object ListTest { def main(args: Array[String]) { // ... 
- 【java基础 14】锁的粒度:ThreadLocal、volatile、Atomic和Synchronized
			导读:题目中提到的几个关键字,分别是解决并发问题中,加锁所使用到的几个关键字,每个关键字代表的锁的粒度 不同,本篇博客,主要是从概念定义上,区分这几个关键字的应用场景.(PS:睡梦中,依稀记得有回面试 ... 
