Description |
n(n<100)组测试数据。每组测试数据输入两个正整数a和b,输出这两个数的最大公约数和最小公倍数。 |
Input |
第一行输入整数n,表示n组测试数据。 以下每行输入两个正整数a和b,数据之间空格分隔。 |
Output |
按格式输出这两个数的最大公约数和最小公倍数。 每组输出数据占两行。 |
Sample Input |
1 45 36 |
Sample Output |
Greatest common divisor is 9 Lease common multiple is 180 |
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int n;
cin>>n;
while(n--)
{
int x,y,x1,y1,temp1,temp2=1;
cin>>x>>y;
x1=x;y1=y;
if(x>y)
{
temp1=x;
x=y;
y=temp1;
}
for(;temp2!=0;)
{
temp2=y%x;
y=x;x=temp2;
}
cout<<"Greatest common divisor is "<<y<<endl;
cout<<"Lease common multiple is "<<x1*y1/y<<endl;
}
return 0;
}