hdu 5019
来源:互联网 发布:网络搬砖是什么意思 编辑:程序博客网 时间:2024/05/18 02:05
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;}
0 0
- hdu 5019
- hdu-5019
- HDU 5019 简单数学题
- hdu 5018 5019
- hdu 5019 gcd
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- zoj 2412 搜索
- [Spring] Spring MVC中@Autowired注释失效的可能原因
- IOKit
- POJ1284_Primitive Roots【欧拉函数】
- storm第一篇--概念,例子,参数优化
- hdu 5019
- deb打包+软件图标+加到系统菜单+安装卸载实例
- set集合 HashSet: TreeSet实现Comparable接口,覆盖compareTo方法。 类实现Comparator接口,覆盖compare方法。
- HDU 4756 Install Air Conditioning(次小生成树)
- 第8周项目1:分段函数求值
- oozie 参数含义
- 算法入门经典第二版(紫书) 第二章 2-1 -> 2-6
- Linux指令笔记3
- Linux指令笔记4