UVA - 11388 GCD LCM
|
II |
|
|
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. |
|
|
Output |
|
|
For each case of input, there will be one line of output. It will contain two positive integers |
|
|
Constraints |
|
|
- T ≤ 100 - Both G and L will be less than |
|
|
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> |
|
UVA - 11388 GCD LCM的更多相关文章
- 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 ...
随机推荐
- mysql导入sql文件过大或连接超时的解决的方法
前段时间出差在现场开发的时候,导入数据库老是出问题.最后发现了一个奇妙sql语句交给实施,仅仅要导入出错就把例如以下语句运行就能够了.至今屡试不爽. set global max_allowed_pa ...
- 总线接口与计算机通信(一)I2C总线
1. I2C总线的基本概念 1)发送器(Transmitter):发送数据到总线的器件 2)接收器(Receiver):从总线接收数据的器件 3)主机(Master):初始化发送. ...
- 平均时间复杂度为O(nlogn)的排序算法
本文包括 1.快速排序 2.归并排序 3.堆排序 1.快速排序 快速排序的基本思想是:采取分而治之的思想,把大的拆分为小的,每一趟排序,把比选定值小的数字放在它的左边,比它大的值放在右边:重复以上步骤 ...
- 解决Charles Response 中文乱码
Response中文乱码:在Info.plist 中 的vmoption 添加-Dfile.encoding=UTF-8 info.plist路径 应用程序->Charles.app->显 ...
- jquery mobile左右滑动切换页面
jquery mobile左右滑动切换页面 $(function() {$("body").bind('swiperight', function() { $.mobile.ch ...
- graph driver-device mapper-04libdevmapper基本操作
// 创建thin pool // 调用路径:NewDeviceSet->initDevmapper->createPool 1.1 func createPool(poolName st ...
- Android原生APP内分享
Android原生APP内分享,可实现数据分享以及assets文件夹分享及私有文件分享 项目地址:https://github.com/json-pu/AndroidAppShare.git
- Java 通过 BufferReader 实现 文件 写入读取 示例
package com.javatest.techzero.gui; import java.io.BufferedReader; import java.io.File; import java.i ...
- iOS进阶面试题----经典10道
OneV‘s Den在博客里出了10道iOS面试题,用他的话是:"列出了十个应聘Leader级别的高级Cocoa/CocoaTouch开发工程师所应该掌握和理解的技术" . 在这 ...
- [Warning] Aborted connection 11203 to db: 'ide' user: 'nuc' host: 'prd01.mb.com' (Got an error writi
PS:一台物理机扯分了3个虚拟机,一个主db,一个主备,一个从备. 切换到0301的时候 Sep 6 09:16:16 prddb0301 mysqld: 130906 9:16:16 [Warn ...