UVa 11388 - GCD LCM

Title: given GCD (a, b) and lcm (a, b), find a, b minimize.

Analysis: Simple question, number theory. If lcm% gcd! = 0 then there is no, or a = gcd, b = lcm.

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4  
 5 int main()
 6 {
 7     int n,G,L; 
 8     while ( scanf("%d",&n) != EOF ) 
 9         for ( int t = 1 ; t <= n ; ++ t ) {
10             scanf("%d%d",&G,&L);
11             if ( L%G == 0 ) 
12                 printf("%d %d\n",G,L);
13             else printf("-1\n");
14         }
15     return 0;
16 }
View Code

 

Guess you like

Origin www.cnblogs.com/ljy08163268/p/11704321.html