#include <stdio.h>
#define type_t long long
type_t gcb(type_t a, type_t b);
type_t lcm(type_t a, type_t b);
void swap1(type_t *, type_t *);
int main()
{
type_t a, b;
while(scanf("%lld%lld",&a , &b) == 2)
{
printf("%lld\n",lcm(a, b));
}
return 0;
}
type_t gcb(type_t a, type_t b)
{
while(a % b)
{
a = a % b;
swap1(&a, &b);
}
return b;
}
type_t lcm(type_t a, type_t b)
{
return a*b/gcb(a,b);
}
void swap1(type_t * a, type_t * b)
{
int temp = *a;
* a = * b;
*b = temp;
}
注意数可能越界,用long long, 其实用unsiged long 就可以了
本文介绍了一个用于计算两个整数的最大公约数(GCD)和最小公倍数(LCM)的C语言程序。该程序利用了辗转相除法来找到最大公约数,并基于此计算出最小公倍数。特别地,为了防止整数溢出,使用了long long类型进行存储。
1128

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



