uva11388】的更多相关文章

UVA11388 GCD LCM Description of the title PDF 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 th…
题目链接. 题意: 给定两个数,一个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和L,求a和b,他们的最大公约数为G和最小公倍数为L,输出a最小时的a和b.如果不存在在输出-1. Sample Input   2 1 2 3 4 Output for Sample Input 1 2 -1   分析: 其实很简单,想到思路就好了,a最小时其实就是G,对应的b必然为L,当L不是G的倍数是不存在a和b 代码: #include<iostream> #include<cstdio> using namespace std; int main()…
因为a,b整除gcd(a,b),lcm(a,b)又整除a,b,因此如果lcm不整除gcd就是-1:否则的话,lcm=a*b/gcd.而a不能小于gcd,因此a就取gcd,b取lcm. #include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <iomanip> #include <c…
(链接点这儿) 题目: 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…
题目大意 \(T\) 组数据,每组数据给定两个整数 \(G,L\),输出数对 \(x,y\) 满足 \(GCD(x,y)=G,LCM(x,y)=L\) 且 \(x\) 最小.若无解则输出 \(-1\). 分析 数论水题.当 \(L\%G=0\) 时有解,且解为 \(x=G,y=L\).这是因为一个整数的因数应当小于等于自身,所以 \(x<G\) 时不成立,而 \(x=G,y=L\) 时恰好成立. #include<bits/stdc++.h> using namespace std; i…