最大公约数和最小公倍数 (GCD LCM,UVa 11388)
1 #include <iostream> 2 #include <string.h> 3 #include <string> 4 #include <fstream> 5 #include <algorithm> 6 #include <stdio.h> 7 #include <vector> 8 #include <queue> 9 #include <set> 10 #include <cmath> 11 using namespace std; 12 const double eps = 1e-8; 13 const int INF=0x7fffffff; 14 #define MAXN 1002 15 typedef long long LL; 16 LL gcd(LL a,LL b) 17 { 18 return b==0?a:gcd(b,a%b); 19 } 20 int main() 21 { 22 int T;scanf("%d",&T); 23 int G,L; 24 while(T--) 25 { 26 scanf("%d%d",&G,&L); 27 if(G%L==0)printf("%d %d\n",L,G); 28 else if(L%G==0)printf("%d %d\n",G,L); 29 else printf("-1\n"); 30 31 } 32 return 0; 33 }
G,L 大小自行判断