数学--数论--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 ...
随机推荐
- 家庭记账本app进度之关于tap的相关操作1
今天还主要学习关于怎样制作微信的先关的tap. 今天的主要成果是已经了解了相关的技术,以及相关的思路.代码经过一个下午的编写,基本接近尾声. 更详细的实验代码,以及相关的知识点将在明天完善后进行发表. ...
- MTK Android Driver :Camera
MTK Android Driver :camera 1.相关代码位置:mediatek\config\XXXX(红色字为具体的项目名) 文件:ProjectConfig.mk CUSTOM_KERN ...
- 安卓动画(Animation使用)
安卓的Animation视图动画的使用非常简单,并且对象适用于一般控件. 具体使用步骤如下. Button/TextView/EditText/ImageView/Bitmap ..... obj ...
- 深入理解智能指针之shared_ptr(一)
本文基于C++标准库源码分析shared_ptr,旨在搞清楚shared_ptr是什么,线程安全性等,目标能够安全的使用智能指针. (一)shared_ptr是一个类. 首先可以确定的是shared_ ...
- 37.2 net-- tcp传输 ServerSocket、Socket
一.打开server端 package day35_net_网络编程.tcp传输; import java.io.IOException; import java.io.InputStream; im ...
- 34.4 对象流 ObjectOutputStream ObjectInputStream
* 对象操作流:可以用于读写任意类型的对象 * ObjectOutputStream * writeObject * ObjectOutputStream(OutputStream out) * Ob ...
- AJ学IOS(25)UI之触摸事件
AJ分享,必须精品 iOS中的事件 在用户使用app过程中,会产生各种各样的事件;iOS中的事件可以分为3大类型: 响应者对象–UIResponder 在iOS中不是任何对象都能处理事件,只有继承了U ...
- Linux环境下django初入
python -m pip install --upgrade pip 终端中 一. 创建项目: 1.django-admin startproject mysite(第一种比较好) 2.django ...
- 2019-05-19 Python之第一个爬虫和测试
一.使用request和get访问某个网页20次并且打印返回状态,内容 扩展:常见状态码含义 200 - 服务器成功返回网页,404 - 请求的网页不存在,403(禁止)服务器拒绝请求,404(未 ...
- 代码质量管理 SonarQube 系列之 安装
简介 SonarQube 是一个开源的代码质量管理系统. 功能介绍: 15种语言的静态代码分析 Java.JavaScript.C#.TypeScript.Kotlin.Ruby.Go.Scala.F ...