`
wss71104307
  • 浏览: 219688 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

problem 1011,求lcm

 
阅读更多
#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 就可以了

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics