【ACM】最小公倍数

http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=1

1
#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int a,b,c,m,n;
	while( scanf( "%d%d" , &n , &m ) != EOF ) {
		if( n > m) {
			a = n ; 
			b = m ;
		} 
		else {
			a = m ; b = n;
		}
		while ( b != 0 ) {  /* 最小公倍数 = m*n/GCD(m,n) */
			c = a % b ; 
			a = b ;
			b = c ; 
		}
		printf( "%d\n" , ( m * n ) /a );
	}
	
	return 0;
}
posted on 2013-12-10 21:51  HelloYou  阅读(309)  评论(0编辑  收藏  举报