II
U C   ONLINE  
C ON TEST 
 2 008

Problem D: GCD LCM

Input: standard input

Output: standard output

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
pairs of numbers. Similarly, it can be the LCM of many pairs of numbers. In this problem, you will be given two positive integers. You have to output a pair of numbers whose GCD is the first number and LCM is the second number.

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 than one pair satisfying the condition, output the pair for which
a is minimized. In case there is no such pair, output -1.

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

题意: 给你两个数的gcd和lcm,让你求时候是唯一的一对n,m,输出最小的一对

思路:设n = a*b*c*d, m = a*b*c*e, 那么gcd=a*b*c, lcm = a*b*c*d*e,那么假设不是唯一的话。那么lcm%gcd != 0,由于d和e的位置能够排列。要唯一的话,一定是lcm是gcd的倍数,且这对就是最小的

#include <iostream>
#include <cstdio>
#include <cstdio>
#include <cstring>
typedef long long ll;
using namespace std; int main() {
int t, n, m;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
if (m % n == 0)
printf("%d %d\n", n, m);
else printf("-1\n");
}
return 0;
}

UVA - 11388 GCD LCM的更多相关文章

  1. UVA 11388 - GCD LCM 水~

    看题传送门 题目大意: 输入两个数G,L找出两个正整数a 和b,使得二者的最大公约数为G,最小公倍数为L,如果有多解,输出a<=b且a最小的解,无解则输出-1 思路: 方法一: 显然有G< ...

  2. UVa 10892 (GCD) LCM Cardinality

    我一直相信这道题有十分巧妙的解法的,去搜了好多题解发现有的太过玄妙不能领会. 最简单的就是枚举n的所有约数,然后二重循环找lcm(a, b) = n的个数 #include <cstdio> ...

  3. Mathematics:GCD & LCM Inverse(POJ 2429)

    根据最大公约数和最小公倍数求原来的两个数 题目大意,不翻译了,就是上面链接的意思. 具体思路就是要根据数论来,设a和b的GCD(最大公约数)和LCM(最小公倍数),则a/GCD*b/GCD=LCM/G ...

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

  5. [POJ 2429] GCD & LCM Inverse

    GCD & LCM Inverse Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 10621   Accepted: ...

  6. POJ 2429 GCD & LCM Inverse(Pollard_Rho+dfs)

    [题目链接] http://poj.org/problem?id=2429 [题目大意] 给出最大公约数和最小公倍数,满足要求的x和y,且x+y最小 [题解] 我们发现,(x/gcd)*(y/gcd) ...

  7. UVA 11426 - GCD - Extreme (II) (数论)

    UVA 11426 - GCD - Extreme (II) 题目链接 题意:给定N.求∑i<=ni=1∑j<nj=1gcd(i,j)的值. 思路:lrj白书上的例题,设f(n) = gc ...

  8. hdu-3071 Gcd & Lcm game---质因数分解+状态压缩+线段树

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3071 题目大意: 给定一个长度为n的序列m次操作,操作的种类一共有三种 查询 L :查询一个区间的所 ...

  9. [ 9.13 ]CF每日一题系列—— 340A GCD & LCM

    Description: [ 着实比较羞愧,都想着去暴力,把算法(方法)也忘了] A只涂x,2x,3x……,B只涂y,2y,3y……问你A和B共同涂的墙的个数 Solution: 就是求x和y的lcm ...

随机推荐

  1. android事件传递机制以及onInterceptTouchEvent()和onTouchEvent()详解二之小秘与领导的故事

    总结的不是很好,自己也有点看不懂,正好现在用到了,研究了一个,再次总结,方便大家查看 总则: 1.onInterceptTouchEvent中有个Intercept,这是什么意思呢?她叫拦截,你大概知 ...

  2. [JBoss] JNDI与JBossNS

    JNDI的作用 JNDI是 Java 命名与目录接口(Java Naming and Directory Interface). 随着分布式应用的发展,远程访问对象访问成为常用的方法.虽然说通过Soc ...

  3. HTTP协议--状态码

    HTTP状态码负责表示客户端HTTP请求返回的结果.标记服务器端的处理是否正常.通知出现的错误等工作. 常用状态码共分5大类: 1XX:Informational,信息性状态码,接收的请求正在处理. ...

  4. UML看书笔记1:主体思想

    对象设计需要解决的三大问题:      1.把“现实世界”映射到“对象世界”      2.从“对象世界”描述“现实世界”      3.验证“对象世界”是否反映了“现实世界” 现实世界与我们的对象世 ...

  5. js打印

    js打印,其实是打印当前页面的内容,是调用 系统的js方法,来弹出 打印设置窗口,用法很简单. window.print()就行,有的考虑到 浏览器兼容性问题,会用到document.execComm ...

  6. python模块介绍- binascii 二进制和ASCII转换

    python模块介绍-binascii二进制和ASCII转换 目录 项目简介 简介: Uu编码 Binhex编码 Base64编码 QP码 CRC校验和 二进制转换 其他实例 项目简介 Python中 ...

  7. VC2008下使用OpenSSL 1.0.0g(免编译)

    OpenSSL整个软件包大概可以分成三个主要的功能部分:密码算法库.SSL协议库以及应用程序. 官网:http://www.openssl.org/OpenSSL for Windows:http:/ ...

  8. perl post发送json数据

    sub  wx_init {                #$login_url ="https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?r=- ...

  9. ANDROID自定义视图——onMeasure流程,MeasureSpec详解

    简介: 在自定义view的时候,其实很简单,只需要知道3步骤: 1.测量——onMeasure():决定View的大小 2.布局——onLayout():决定View在ViewGroup中的位置 3. ...

  10. Convert QWERTY to Dvorak

      Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Pract ...