UVA 11388-GCD LCM(数学)
|
I I U C O N L I N E |
|
|
Problem D: GCD LCM |
|
|
Input: standard input |
|
|
The GCD of two positive integers is the largest integer that divides both the integers without any remainder. The LCM of two positive integers is the smallest positive integer that is divisible by both the integers. A positive integer can be the GCD of many |
|
|
Input |
|
|
The first line of input will consist of a positive integer T. T denotes the number of cases. Each of the next T lines will contain two positive integer, G and L. |
|
|
Output |
|
|
For each case of input, there will be one line of output. It will contain two positive integers a and b, a ≤ b, which has a GCD of G and LCM of L. In case there is more |
|
|
Constraints |
|
|
- T ≤ 100 - Both G and L will be less than 231. |
|
|
Sample Input |
Output for Sample Input |
|
2 1 2 3 4 |
1 2 -1 |
|
Problem setter: Shamim Hafiz 题意 :给出两个数G,L,问是否存在一对数a,b。使得gcd(a,b)==G,lcm(a,b)==L; 能够这么想:当gcd(G,L)==G(a),lcm(G,L)==L(b)时。此时G==a,L==b,满足上述条件。否则不成立。
#include <cstdio> |
|
版权声明:本文博主原创文章,博客,未经同意不得转载。
UVA 11388-GCD LCM(数学)的更多相关文章
- UVA - 11388 GCD LCM
II U C ONLINE C ON TEST Problem D: GCD LCM Input: standard input Output: standard output The GC ...
- UVA 11388 - GCD LCM 水~
看题传送门 题目大意: 输入两个数G,L找出两个正整数a 和b,使得二者的最大公约数为G,最小公倍数为L,如果有多解,输出a<=b且a最小的解,无解则输出-1 思路: 方法一: 显然有G< ...
- UVa 10892 (GCD) LCM Cardinality
我一直相信这道题有十分巧妙的解法的,去搜了好多题解发现有的太过玄妙不能领会. 最简单的就是枚举n的所有约数,然后二重循环找lcm(a, b) = n的个数 #include <cstdio> ...
- 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: ...
- POJ 2429 GCD & LCM Inverse(Pollard_Rho+dfs)
[题目链接] http://poj.org/problem?id=2429 [题目大意] 给出最大公约数和最小公倍数,满足要求的x和y,且x+y最小 [题解] 我们发现,(x/gcd)*(y/gcd) ...
- UVA 11426 - GCD - Extreme (II) (数论)
UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gc ...
- hdu-3071 Gcd & Lcm game---质因数分解+状态压缩+线段树
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3071 题目大意: 给定一个长度为n的序列m次操作,操作的种类一共有三种 查询 L :查询一个区间的所 ...
- [ 9.13 ]CF每日一题系列—— 340A GCD & LCM
Description: [ 着实比较羞愧,都想着去暴力,把算法(方法)也忘了] A只涂x,2x,3x……,B只涂y,2y,3y……问你A和B共同涂的墙的个数 Solution: 就是求x和y的lcm ...
随机推荐
- 创建android画笔程序的样例(有镜面效果)
先上图: 关键是在检測到手指移动的时候用mPath.quadTo的方法,android sdk解释是: Add a quadratic bezier from the last point, appr ...
- pdftk的使用介绍
首先像下面的一页pdf,如果想把它分成两页,每一页只是一个ppt页面(为了在kindle里读比较方便), 那么可以首先用A-pdf page cut, 将pdf 切成这样12个部分 然后我们现在要的只 ...
- Ajaxterm
Index of /software/ajaxterm Ajaxterm Since Mon Feb 28 03:22:42 CET 2011, hosted here: github.com/ant ...
- Docker 用法总结之:管理工具 shipyard 的具体使用指南
Docker 的命令行就已经非常好用了,假设非要加上基于 Web 的管理界面的话也有一些选择,如 DockerUI (Angular.js), Dockland (Ruby), Shipyard (P ...
- Python 类继承,__bases__, __mro__, super
Python是面向对象的编程语言,也支持类继承. >>> class Base: ... pass ... >>> class Derived(Base): ... ...
- Linux for周期运行命令注意事项
假定for有一些符号循环指令,需要使用()封闭. for i in {1..4}; do (python /data/UGCRobot/manage/Scheduler.py 1.log > / ...
- H3C TE BGP拓扑排错报告
BGP排错报告 故障一:PPP链路 ...
- 【译】ASP.NET MVC 5 教程 - 3:添加视图
原文:[译]ASP.NET MVC 5 教程 - 3:添加视图 在本节内容中,我们将修改HelloWorldController类,使用视图模板来干净利索的封装生成HTML响应客户端的过程. 您将创建 ...
- (转载)浅析error LNK2001: unresolved external symbol "public: __thisc...
学习VC++时经常会遇到链接错误LNK2001,该错误非常讨厌,因为对于 编程者来说,最好改的错误莫过于编译错误,而一般说来发生连接错误时, 编译都已通过.产生连接错误的原因非常多 ...
- 使用SVNkit删除版本库的文件
源网址:http://wiki.svnkit.com/Committing_To_A_Repository Editing Operation: commiting to a repository T ...