UVa 11388 & 丝帛】的更多相关文章

一直在想丝帛题要不要贴呢...后来觉得还是贴了吧...反正没人看...blog是开给自己看的...偶尔无聊打打blog也显得生活非常充实... 题意: 给一个gcd和lcm求满足啊他们的最小的a和b. SOL: 还想着质因数分解来着...转念一想比gcd小的数的gcd也不能变成G啊...这不是丝帛么...那最小的不就是gcd么... 数论用几个丝帛题开头好了 = =... Code: #include <cstdio> #include <cstdlib> #include <…
这道题是关于两个数的最大公约数和最小公倍数的题目.给你两个数字g,l,分别表示最大公约数和最小公倍数.要求你找到两个数a,b,要求这两个数的最大公约数和最小公倍数为所给的两个数.如果存在多组数字符合这一条件, 就输出a最小的那一组数字.由最大公约数和最小公倍数与两个数的关系可得,a*b=l*g,g<=a,b<=l,a%g==b%g==0,l%a==l%b==0.则所要求的a最小的那组数据,其实就是当a==g时所求出的那组数据. #include <stdio.h> #include…
II U C   ONLINE   C ON TEST  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 smalle…
题目链接: https://cn.vjudge.net/problem/23709/origin 本题其实有坑 数据大小太大, 2的32次方,故而一定是取巧的算法,暴力不可能过的 思路是最大公因数的倍数是最小公倍数,又有a <= b所以可以知道 a = gcd, b = lcm AC代码如下: #include <cstdio> #define ll long long using namespace std; int main() { int T; scanf("%d&quo…
代码很短理解不容易,在这说不清,大家代码里寻真相. 为什么二者相除就可以A了多找点数试试理解理解. #include<stdio.h> #define mod 1000000007 #define ll long long int main() { ll G, L,n; int t; scanf("%d",&t); while(t--) { scanf("%lld %lld",&G,&L); ) printf("%lld…
两个数的最小公倍数和最大公约数肯定是倍数关系 然后又让求使得a最小  因为 a = m * gcd 令m = 1 时 a取得最小  即gcd 则b = lcm #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <queue> #include <vector> #include <cmath> #de…
题意:给出G和L,求最小的a使得gcd(a,b)=G,lcm(a,b)=L 显然a>=G,所以a取G,b要满足质因子质数为L的同次数,b取L //此处应有代码…
看题传送门 题目大意: 输入两个数G,L找出两个正整数a 和b,使得二者的最大公约数为G,最小公倍数为L,如果有多解,输出a<=b且a最小的解,无解则输出-1 思路: 方法一: 显然有G<= a <=b <=L成立.题目要求(a<=b) 所以如果有解,a最小值只能为G. a * b = G * :L所以 b = L 什么时候无解呢? 如果L 不能整除 G 就无解了嘛. #include<cstdio> int main() { int T; scanf("…
UVA - 11388 GCD LCM 题意:输入g和l,找到a和b,gcd(a,b)=g,lacm(a,b)=l,a<b且a最小 g不能整除l时无解,否则一定g,l最小 #include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> using namespace std; typedef long long ll…
√√第一部分 基础算法(#10023 除外) 第 1 章 贪心算法 √√#10000 「一本通 1.1 例 1」活动安排 √√#10001 「一本通 1.1 例 2」种树 √√#10002 「一本通 1.1 例 3」喷水装置 √√#10003 「一本通 1.1 例 4」加工生产调度 √√#10004 「一本通 1.1 例 5」智力大冲浪 √√#10005 「一本通 1.1 练习 1」数列极差 √√#10006 「一本通 1.1 练习 2」数列分段 √√#10007 「一本通 1.1 练习 3」线…