最大公约数和最小公倍数 (15 分)
本题要求两个给定正整数的最大公约数和最小公倍数。
输入格式:
输入在一行中给出两个正整数M和N(≤1000)。
输出格式:
在一行中顺序输出M和N的最大公约数和最小公倍数,两数字间以1空格分隔。
输入样例:
511 292
输出样例:
73 2044
/*最大公约数和最小公倍数*/
#include <iostream>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
using namespace std;
int main(void){
int m,n;
int d;
scanf("%d%d",&m,&n);
int a = m;
int b = n;
while(n!=0)
{
d = m % n;
m = n;
n = d;
}
int A = a / m;
int B = b / m;
int S = A*B*m;
printf("%d %d\n",m,S);
return 0;
}