http://acm.hdu.edu.cn/showproblem.php?pid=5019

给出X 和Y,求出第K 大的 X 和Y 的公约数。

暴力求出所有公约数

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include<set>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
LL gcd(LL a,LL b){ return b == 0? a:gcd(b,a%b);}
LL x,y,k;
LL p[1000005];
LL cmp(LL a,LL b)
{
return a > b;
}
int main() {
int _;
RD(_);
while(_--){
int cnt = 0;
scanf("%I64d%I64d%I64d",&x,&y,&k);
LL op = gcd(x,y);
for(LL i = 1;i < (int)sqrt(op)+1;++i){
if(op%i == 0){
p[cnt++] = i;
if(i*i != op){
p[cnt++] = op/i;
}
}
}//cout<<cnt;
sort(p,p+cnt,cmp);
if(cnt < k){
puts("-1");
}
else{
printf("%I64d\n",p[k-1]);
}
} return 0;
}

hdu 5019的更多相关文章

  1. BestCoder10 1002 Revenge of GCD(hdu 5019) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 题目意思:给出 X 和 Y,求出 第 K 个 X 和 Y 的最大公约数. 例如8 16,它们的公 ...

  2. HDU 5019 Revenge of GCD(数学)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest ...

  3. HDU 5019 Revenge of GCD

    题解:筛出约数,然后计算即可. #include <cstdio> #include <algorithm> typedef long long LL; LL a1[10000 ...

  4. hdu 5019(第K大公约数)

    Revenge of GCD Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. 数学--数论--HDU 5019 revenge of GCD

    Revenge of GCD Problem Description In mathematics, the greatest common divisor (gcd), also known as ...

  6. xudyh的gcd模板

    hdu 5019 #include <cstdlib> #include <cctype> #include <cstring> #include <cstd ...

  7. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  9. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

随机推荐

  1. dns server 配置

    # cat /etc/named.conf//// named.conf//// Provided by Red Hat bind package to configure the ISC BIND ...

  2. Spring依赖注入:基于xml配置

    基础接口 BeanFactory.ApplicationContext. BeanFactory用于创建并管理.获取各种类的对象. ApplicationContext从BeanFactory派生而来 ...

  3. 第八章 高级搜索树 (b1)B-树:动机

  4. The Unique MST

    The Unique MST http://poj.org/problem?id=1679 Time Limit: 1000MS   Memory Limit: 10000K Total Submis ...

  5. Robotium原理初步--Android自动化测试学习历程

    章节:自动化基础篇——Robotium原理初步(第四讲) 主要讲解内容与笔记: 一.基于控件 1.spinner——下拉菜单 2.TabHost——左右滑动选择菜单,类似电话本 3.Gallery—— ...

  6. ecplice中代码使用快捷键无法格式化,使用其他方法将代码格式化的步骤

    选中需要进行格式化的代码--->右键--->source--->format,就可以将代码格式化了.

  7. 品味性能之道<七>:索引基础

    一.索引概述      索引(index),它是数据库必不可少的一部分.它其实很简单呐!很好理解.      索引好比如一本书的目录,一张地图,一个写字楼里挂在大堂墙上的公司名录,一个地铁站的出口指示 ...

  8. 2018年上半年UI领域主要的13个设计趋势

    2018年时间过半,通过过去的6个月的观察,其实我们已经可以对于2018年的整个UI领域的设计趋势有了一个更为清晰的判断. 也是推出这篇文章比较合理的时机.下面我们就一起来回顾一下,过去的半年当中,U ...

  9. 使用 Php Artisan Tinker 来调试你的 Laravel

    Posted on 2016年6月19日 by ichou 本文翻译自:Tinker with the Data in Your Laravel Apps with Php Artisan Tinke ...

  10. 彻底关闭win10的自动更新,一定要坚持看到最后一页

    https://jingyan.baidu.com/article/9faa7231e7b78b473c28cbb6.html 是否好使我还在测试,不好使的话,再跟新 2018-05-20 今天电脑又 ...