Common Divisor and public multiple
DescriptionJames was troubled by a problem. Now I need your help. The problem is: two positive integers are given to obtain their maximum common approx. And the least common multiples.
-
Input
-
Enter an integer N (0 <n <= 10000) in the first row, indicating that there are N groups of test data. Then, input two integers I, j (0 <I, j <= 32767 ).
-
Output
-
Output the maximum and least common multiples of each group of test data
-
Sample Input
-
36 612 1133 22
-
Sample output
-
6 61 13211 66
#include<iostream>using namespace std;int gcd(int a,int b){ int min=(a<b)?a:b; int max=(a>b)?a:b; while(min!=0) { int k = max%min; max=min; min=k; } return max;}int main(){ int test ; int num1,num2; cin>>test; while(test--) { cin>>num1>>num2; int kk = (num1 * num2)/gcd(num1,num2); cout<<gcd(num1,num2)<<" "<<kk<<endl; } return 0;}
Common Divisor and public multiple