Bestcoder #10 hdoj5019
来源:互联网 发布:数控车凹圆弧编程实例 编辑:程序博客网 时间:2024/06/01 07:40
题目链接
题目描述
求AB的第K大公约数
思路
枚举AB所有公因子(
代码如下
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#include <cmath>using namespace std;const long long INF = 1000000000;long long ans[1001000];long long gcd(long long x, long long y){ if(y == 0) return x; return gcd(y,x%y);}int main(){ int T; scanf("%d",&T); while(T--) { long long x,y,k; scanf("%lld%lld%lld",&x,&y,&k); if(x < y) swap(x,y); long long g = gcd(x,y); long long d = sqrt(g); long long r = 0; // memset(ans,INF,sizeof(ans)); int re = 0; for(int i = 1; i<=d; i++) { if(g%i == 0) { ans[r++] = i; long long ca = g/i; if(ca != i) ans[r++] = ca; } } sort(ans, ans+r); if(k>r) printf("-1\n"); else printf("%lld\n",g/ans[k-1]); }}
0 0
- Bestcoder #10 hdoj5019
- [BestCoder] Round #10
- Bestcoder #10 hdoj5018
- BestCoder
- bestcoder
- BestCoder Round #10(解题报告)
- hdu 5018 Revenge of Fibonacci(BestCoder Round #10)
- hdu 5019 Revenge of GCD(BestCoder Round #10)
- BestCoder 20140727
- BestCoder#3
- Bestcoder #11
- bestcoder #14
- BestCoder #20
- bestcoder lines
- BestCoder#27
- BestCoder#29
- bestcoder Delete
- bestcoder Mutiple
- 【JavaScript】DOM编程-DHTML与Windows对象
- Java设计模式-2-工厂方法模式
- 自学宝典:10个学习Android开发的网站推荐
- jstl函数-split
- Nodejs在Ubuntu下安装
- Bestcoder #10 hdoj5019
- [Android]_[初级]_[Android开发环境搭建入门(Windows)]
- C++ STL MAP 使用方法与应用介绍
- jstl-自定义函数
- 文章发布系统
- UITextField
- 2014年度智慧城市盘点:大概念如何落地?
- matlab 找拐点 (papa的儿子,儿子的papa)
- 蓝桥杯 最短路