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

Problem Description
In
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.

 
Input
The first line contains a single integer T, indicating the number of test cases.

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

 
Output
For each test case, output the k-th GCD of X and Y. If no such integer exists, output -1.
 
Sample Input
3
2 3 1
2 3 2
8 16 3
 
Sample Output
1
-1
2
 
Source
 
被坑惨了。。GCD的参数传的INT。。求出最大公约数然后求最大公约数的第K大因子就好。
#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大公约数)的更多相关文章

  1. __gcd-最大公约数

    __gcd-最大公约数 最大公约数(greatest common divisor,简写为gcd:或highest common factor,简写为hcf) __gcd(x,y)是algorithm ...

  2. hdu 4542 打表+含k个约数最小数

    http://acm.hdu.edu.cn/showproblem.php?pid=4542 给出一个数K和两个操作 如果操作是0,就求出一个最小的正整数X,满足X的约数个数为K. 如果操作是1,就求 ...

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

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

  4. HDU 5019 Revenge of GCD(数学)

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

  5. hdu 5019

    http://acm.hdu.edu.cn/showproblem.php?pid=5019 给出X 和Y,求出第K 大的 X 和Y 的公约数. 暴力求出所有公约数 #include <cstd ...

  6. hdu 2639 第k大01背包

    求每个状态里的k优解,然后合并 /* HDU 2639 求01背包的第k大解. 合并两个有序序列 */ #include<stdio.h> #include<iostream> ...

  7. HDU 5019 Revenge of GCD

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

  8. HDU 6342.Problem K. Expression in Memories-模拟-巴科斯范式填充 (2018 Multi-University Training Contest 4 1011)

    6342.Problem K. Expression in Memories 这个题就是把?变成其他的使得多项式成立并且没有前导零 官方题解: 没意思,好想咸鱼,直接贴一篇别人的博客,写的很好,比我的 ...

  9. 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 ...

随机推荐

  1. 【计数】hdu5921Binary Indexed Tree

    二进制拆位计算贡献 题目描述 树状数组是一种常用的数据结构,下面是树状数组用于给区间 [1,x] 内的数加 t 的代码: void add(int x,int t){ for (int i=x;i;i ...

  2. pandas处理大文本数据

    当数据文件是百万级数据时,设置chunksize来分批次处理数据 案例:美国总统竞选时的数据分析 读取数据 import numpy as np import pandas as pdfrom pan ...

  3. Re:从零开始的Linux之路(目录配置)

    基于 Red Hat Enterprise Linux 7.5 或者 CentOS 7.4 FHS协议(Filesystem Hierarchy Standard)——文件系统层次化标准 该标准定义了 ...

  4. vue_music:封装scroll.vue组件

    在项目中经常用到滚动,结合Better-scroll封装了sroll.vue组件参考链接:https://ustbhuangyi.github.io...http://www.imooc.com/ar ...

  5. overtrue/wechat 包 由 sys_get_temp_dir 引发的 the directory "c:\Windows" is not writable

    vendor\overtrue\wechat\src\Foundation\Application.php registerBase 方法 在初始化属性时 $this['cache'] = funct ...

  6. Spring MVC+Mybatis 多数据源配置及发现的几个问题

    1.CustomerContextHolder 数据源管理类,负责管理当前的多个数据源,基于ThreadLocal实现,对每个线程设置不同的目标数据源 public class CustomerCon ...

  7. Windows中redis的下载及安装、设置

    本文是转载自:https://www.cnblogs.com/wxjnew/p/9160855.html 除了原文的东西还有自己遇到的一些问题,这里记录一下. 一.下载: 下载地址: https:// ...

  8. spring boot 启动慢的原因

    停留在Spring logo那里差不多4分钟 SpringBoot启动慢的原因应该是某些应用占用了spring config server默认的端口8888,然后SpringCloud进程有些引用了s ...

  9. uiautomatorviewer打不开

    uiautomatorviewer打不开: 因为之前我下载的jdk版本为10,后来将jdk版本改为8之后就可以打开了.

  10. SCOI 2010 滑雪

    题目描述 a180285非常喜欢滑雪.他来到一座雪山,这里分布着 MM 条供滑行的轨道和 NN 个轨道之间的交点(同时也是景点),而且每个景点都有一编号 ii ( 1 \le i \le N1≤i≤N ...