HDU1108

来源:互联网 发布:微博营销数据分析 编辑:程序博客网 时间:2024/06/02 05:55

最小公倍数




Problem Description
给定两个正整数,计算这两个数的最小公倍数。
 

Input
输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.
 

Output
对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。
 

Sample Input
10 14
 

Sample Output
70
//HDU1108 基础题//最小公倍数http://acm.hdu.edu.cn/showproblem.php?pid=1108//2017.08.24 by wyj/*Problem Description给定两个正整数,计算这两个数的最小公倍数。Input输入包含多组测试数据,每组只有一行,包括两个不大于1000的正整数.Output对于每个测试用例,给出这两个数的最小公倍数,每个实例输出一行。Sample Input10 14Sample Output70*/#includeusing namespace std;int GCD(int a, int b){int temp, r;if (a < b){temp = a;a = b;b = temp;}while ((r = a%b) != 0){a = b;b = r;}return b;}int LCM(int a, int b){int GCD(int a, int b);int h;h = GCD(a, b);return a*b / h;}int main(){int x, y;while (scanf("%d%d", &x, &y) != EOF) {printf("%d\n", LCM(x, y));}return 0;}