Problem Description
给定两个正整数,计算这两个数的最小公倍数。
Input
输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.
Output
对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。
Sample Input
10 14
Sample Output
70
//思路,最小公倍数=两数之积除以两数最大公约数
#include<stdio.h>
#include<stdlib.h>
int GCD(int a,int b)
{
if(b==0)return a;
else return GCD(b,a%b);
}
int main()
{
int a,b,gcd;
while(scanf("%d %d",&a,&b)!=EOF)
{
if(a<b)
{
gcd=GCD(b,a);
}
else
{
gcd=GCD(a,b);
}
printf("%d\n",a*b/gcd);
}
system("pause");
return 0;
}
最小公倍数计算算法详解

4331

被折叠的 条评论
为什么被折叠?



