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. 更新日志(建议升级到2017.1.18a) && 更新程序的方法

    更新程序的步骤: 1,在控制面板里点击备份当前数据库文件到磁盘,把当天获取的信息从内存写到磁盘/存储卡.2,下载最新版的源码 wget -O "infopi.zip" " ...

  2. rabbitmq web管理界面 用户管理

    安装最新版本的rabbitmq(3.3.1),并启用management plugin后,使用默认的账号guest登陆管理控制台,却提示登陆失败. 翻看官方的release文档后,得知由于账号gues ...

  3. 杨辉三角(生成器generator)

    生成器:(Python中,这种一边循环一边计算的机制,称为生成器:generator) 创建generator的方法: 1.把列表生成式的[]变为(),就创建了一个generator 例: 可以通过n ...

  4. Android热修复(HotFix)实战

    线上的BUG一直是程序员头疼的问题.有时候仅仅是因为几行的代码,就能让你的用户损失严重.谷歌在Android Studio 加入了Insttan Run 机制.通过Apk动态加载的技术实现了应用非安装 ...

  5. 支付宝SDK ios快捷支付

    配置PartnerConfig.h的参数 //合作身份者id,以2088开头的16位纯数字 #define PartnerID @"" //收款支付宝账号 #define Sell ...

  6. Mongodb相对于关系型数据库的优缺点(转)

    与关系型数据库相比,MongoDB的优点: ①弱一致性(最终一致),更能保证用户的访问速度: 举例来说,在传统的关系型数据库中,一个COUNT类型的操作会锁定数据集,这样可以保证得到“当前”情况下的精 ...

  7. 《Ubuntu标准教程》学习总结

    第6章 Shell Shell就是一个命令解释器,负责完成用户与内核之间的交互. 目前流行电Shell主要有:Bourne Shell( sh ).Bourne Again Shell( Bash ) ...

  8. [NOI.AC]COUNT(数学)

    解析: 也可以将所有的可能都计算出来,后进行减法运算. 代码: #include<bits/stdc++.h> using namespace std; #define ll long l ...

  9. PS、AI、AE常用快捷键大全

    PS,AI,AE最常用的快捷键来了. 注意:Mac用户请自觉把Ctrl换成Command理解就行. 2017 Adobe Photoshop CC 快捷键 2017Adobe Illustrator快 ...

  10. Jmeter中正则表达式不区分大小写进行匹配

    (?i)<r i="([A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12})" ...