UVA11388 GCD LCM(数论)
题目链接。
题意:
给定两个数,一个G,一个L,找出两个数a,b(a<=b),使得这两个数的最大公约数为G,最小公倍数为L,且(a最小)。
分析:
当a,b存在时,a一定为G。
自己证了一下,数学方面不太擅长。
假设 a 最小为 k1G (其中 k1 != 1), b为 k2G, 即 a = G,不满足条件。
那么a*b=k1*k2*G^2=L*G
这时一定有 a1 = G, b2 = k1*k2G 满足条件。即a不符合题意。
设 a = G, b = kG
因为 L*G = a*b
b = L*G/a = L.
因为b = kG
b/a=kG/G=k
所以要满足的条件为 L % G == 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath> using namespace std; const int maxn = +; typedef long long LL; int main() {
// freopen("my.txt", "r", stdin);
int T;
LL G, L; scanf("%d", &T); while(T--) {
while(cin >> G >> L) {
if(L % G) cout << "-1\n";
else cout << G << ' ' << L << endl;
}
} return ;
}
UVA11388 GCD LCM(数论)的更多相关文章
- 洛谷 UVA11388 GCD LCM
UVA11388 GCD LCM Description of the title PDF The GCD of two positive integers is the largest intege ...
- UVA11388 GCD LCM
(链接点这儿) 题目: The GCD of two positive integers is the largest integer that divides both the integers w ...
- 2015多校第8场 HDU 5382 GCD?LCM! 数论公式推导
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5382 题意:函数lcm(a,b):求两整数a,b的最小公倍数:函数gcd(a,b):求两整数a,b的最 ...
- 数论入门2——gcd,lcm,exGCD,欧拉定理,乘法逆元,(ex)CRT,(ex)BSGS,(ex)Lucas,原根,Miller-Rabin,Pollard-Rho
数论入门2 另一种类型的数论... GCD,LCM 定义\(gcd(a,b)\)为a和b的最大公约数,\(lcm(a,b)\)为a和b的最小公倍数,则有: 将a和b分解质因数为\(a=p1^{a1}p ...
- 【HDU 5382】 GCD?LCM! (数论、积性函数)
GCD?LCM! Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total ...
- 数论3——gcd&&lcm
gcd(a, b),就是求a和b的最大公约数 lcm(a, b),就是求a和b的最小公倍数 然后有个公式 a*b = gcd * lcm ( gcd就是gcd(a, b), ( •̀∀•́ ) ...
- Mathematics:GCD & LCM Inverse(POJ 2429)
根据最大公约数和最小公倍数求原来的两个数 题目大意,不翻译了,就是上面链接的意思. 具体思路就是要根据数论来,设a和b的GCD(最大公约数)和LCM(最小公倍数),则a/GCD*b/GCD=LCM/G ...
- POJ 2429 GCD & LCM Inverse (Pollard rho整数分解+dfs枚举)
题意:给出a和b的gcd和lcm,让你求a和b.按升序输出a和b.若有多组满足条件的a和b,那么输出a+b最小的.思路:lcm=a*b/gcd lcm/gcd=a/gcd*b/gcd 可知a/gc ...
- [POJ 2429] GCD & LCM Inverse
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10621 Accepted: ...
随机推荐
- [AWS S3] Hosting a Static Website on Amazon S3
In this lesson, you will learn how to host a static website on Amazon S3. I will show you how to cre ...
- How To Cluster Rabbit-MQ--reference
Foreword This explanation of clustering Rabbit-MQ assumes that you’ve had some experience with Rabbi ...
- HDU 5119 Happy Matt Friends(dp+位运算)
题意:给定n个数,从中分别取出0个,1个,2个...n个,并把他们异或起来,求大于m个总的取法. 思路:dp,背包思想,考虑第i个数,取或者不取,dp[i][j]表示在第i个数时,异或值为j的所有取法 ...
- css 圆角效果
http://intacto10years.com/index_start.php<div style="width:800px; height:1300px;">&l ...
- Wpf 数据绑定简介、实例1
简介:1.WPF绑定使用的源属性必须是依赖项属性,这是因为依赖项属性具有内置的更改通知支持,元素绑定表达式使用了Xaml扩展标记, WPF绑定一个控件是使用Binding.ElementName, 绑 ...
- Content-Disposition的使用和注意事项
转载:http://www.cnblogs.com/jzaileen/articles/1281025.html 最近不少Web技术圈内的朋友在讨论协议方面的事情,有的说web开发者应该熟悉web相关 ...
- Mac 安装maven3.3.9
只记录一部分自己出错的内容 maven 3 与 jdk 版本的关系 之前安装的jdk是1.8 安装完maven(包括配置环境变量)之后,输入mvn -version 显示版本错误 ,百度之后发现是ma ...
- XML样本(格式没区别,但是一个有结果 一个没结果)
xml样本01<orderlist> <order> <orderid>1</orderid> <ord ...
- Android学习----发行版本
Android 1.1(Bender“发条机器人”) Android 1.5( Cupcake“纸杯蛋糕”) Android 1.6(Donut 甜甜圈) Android 2.0(Éclair:闪电泡 ...
- Linux(Debian)上安装Redis教程
-- 第一步下载文件到该目录 cd /usr/local/src wget http:.tar.gz 解压 tar xzf redis.tar.gz -- 第二步编译安装 make make all ...