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…
看题传送门 题目大意: 输入两个数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("…