数学--数论--HDU 5019 revenge of GCD
Revenge of GCD
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 <= T <= 100
- 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
for循环暴力求即可
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
long long x[500000], a, b, k;
int main()
{
int t;
scanf("%d", &t);
while (t--)
{
memset(x, 0, sizeof(x));
scanf("%lld%lld%lld", &a, &b, &k);
long long d = __gcd(a, b);
long long i, j = 0;
for (i = 1; i * i <= d; ++i)
{
if (d % i == 0)
{
x[j++] = i;
if (i * i != d)
x[j++] = d / i;
}
}
if (j < k)
{
printf("-1\n");
}
else
{
sort(x, x + j);
printf("%lld\n", x[j - k]);
}
}
return 0;
}
数学--数论--HDU 5019 revenge of GCD的更多相关文章
- HDU 5019 Revenge of GCD(数学)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5019 Problem Description In mathematics, the greatest ...
- HDU 5019 Revenge of GCD
题解:筛出约数,然后计算即可. #include <cstdio> #include <algorithm> typedef long long LL; LL a1[10000 ...
- HDOJ 5019 Revenge of GCD
Revenge of GCD In mathematics, the greatest common divisor (gcd), also known as the greatest common ...
- 数学--数论--HDU 4675 GCD of Sequence(莫比乌斯反演+卢卡斯定理求组合数+乘法逆元+快速幂取模)
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N i ...
- 数学--数论--HDU 5223 - GCD
Describtion In mathematics, the greatest common divisor (gcd) of two or more integers, when at least ...
- 数学--数论--HDU 5382 GCD?LCM?(详细推导,不懂打我)
Describtion First we define: (1) lcm(a,b), the least common multiple of two integers a and b, is the ...
- 数学--数论--HDU 1792 A New Change Problem (GCD+打表找规律)
Problem Description Now given two kinds of coins A and B,which satisfy that GCD(A,B)=1.Here you can ...
- 数学--数论--HDU 2582 F(N) 暴力打表找规律
This time I need you to calculate the f(n) . (3<=n<=1000000) f(n)= Gcd(3)+Gcd(4)+-+Gcd(i)+-+Gc ...
- 数学--数论--HDU - 6395 Let us define a sequence as below 分段矩阵快速幂
Your job is simple, for each task, you should output Fn module 109+7. Input The first line has only ...
随机推荐
- 开学java的初步考试
//第一个.java文件 package project1; //20183777 温学智 信1805-2 public class ScoreInformation { private String ...
- Android AndroidManifest.xml详解
AndroidManifest.xml简述: AndroidManifest.xml 是每个android程序中必须的文件.它位于整个项目的根目录,描述了package中暴露的组件(activitie ...
- AJ学IOS(35)UI之Quartz2D仿真支付宝手势解锁_代理获得密码。
AJ分享,必须精品 效果: 实现步骤 其实这个实现起来不难 第一步先放好主要的UI,一张背景图和一个View 第二部就是把9个button放到view中,设置好按钮的默认和选中图片. 注意:创建时候的 ...
- 基于my-DAQ的温室迷你温室设计
这是一个小项目,采用NI的my-DAQ做数据采集,需要采集的数据有温度(LM35),气体(MQ2),需要控制的设备有风扇.加热棒,另外还有光照亮度调节. 一.数据采集 1.LM35 LM35是模拟输出 ...
- Salesforce 开发 | Salesforce与微信集成实操指南
配置前须知 Salesforce通过试点对特定客户提供Lightning WeChat Messaging,该试点需要同意特定的条款.除非Salesforce宣布WeChat Messaging全面可 ...
- Hadoop权威指南(中文版-带目录索引)pdf电子书
Hadoop权威指南(中文版-带目录索引)pdf电子书下载地址:百度网盘点击下载:链接:https://pan.baidu.com/s/1E-8eLaaqTCkKESNPDqq0jw 提取码:g6 ...
- lua使用笔记1:Linux 中安装lua
1.lua安装 1)http://www.lua.org/download.html为下载页面 linux中运行 wget http://www.lua.org/ftp/lua-5.2.3.tar.g ...
- 格式化启动盘win10
我这个(U盘)磁盘被分成了两个区,不能直接格式化 第一步: 第二步: 删除完了之后,选择格式化,ok. 说明:格式化时要选择系统. 常规NTFS 缺点:老设备,比如打印机,监控机识别不了. FAT系 ...
- Go gRPC进阶-go-grpc-middleware使用(八)
前言 上篇介绍了gRPC中TLS认证和自定义方法认证,最后还简单介绍了gRPC拦截器的使用.gRPC自身只能设置一个拦截器,所有逻辑都写一起会比较乱.本篇简单介绍go-grpc-middleware的 ...
- Spring Boot 中使用自定义注解,AOP 切面打印出入参日志及Dubbo链路追踪透传traceId
一.使用背景 开发排查系统问题用得最多的手段就是查看系统日志,在分布式环境中一般使用 ELK 来统一收集日志,但是在并发大时使用日志定位问题还是比较麻烦,由于大量的其他用户/其他线程的日志也一起输出穿 ...