Description
Write a program that reads in two integers and finds their least common multiple (LCM). The LCM of two numbers is the smallest number that is a multiple of both. For example, the LCM for 8 and 12 is 24, for 15 and 25 is 75, and for 120 and 2 is 120.
Input
The first line is a positive integer t for the number of test cases.
Each test case contains one line with two positive integers n1 and n2.
0<n1<100000, 0<n2<100000.
Output
For each test case, output “test case #testcaseNum:” in first line, then output another line with the format:
n1 n2 LCM
Sample Input
Copy sample input to clipboard
2
15 25
120 2
Sample Output
test case 1:
15 25 75
test case 2:
120 2 120
// Date:2020/5/1
// Author:xiezhg5
#include <stdio.h>
#include <math.h>
int GCD(int a,int b);
int LCM(int a,int b);
int main(void) {
int i,m,n,t,k;
scanf("%d",&t);
for(i=1; i<=t; i++) {
scanf("%d %d",&m,&n);
k=LCM(m,n);
printf("test case %d:\n%d %d %d\n",i,m,n,k);
}
return 0;
}
//求a b的最大公約數
int GCD(int a,int b) {
int r,t;
if(a<b) {
t=a;
a=b;
b=t;
}
while(r=a%b) {
a=b;
b=r;
}
return b;
}
//求a b的最大公倍數
int LCM(int a,int b) {
int n=GCD(a,b);
int m;
m=a*b/n;
return m;
}