您的位置:首页 > 其它

【ACM】最小公倍数

2013-12-10 21:51 169 查看
http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2§ionid=1&problemid=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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: