现在的位置: 首页 > 综合 > 正文

hdu 1108 最小公倍数(水题)

2017年11月23日 ⁄ 综合 ⁄ 共 404字 ⁄ 字号 评论关闭

思路:辗转相除法

代码:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>

using namespace std;

#define mst(a,b) memset(a,b,sizeof(a))
#define eps 10e-8

const int MAX_ = 10010;

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}

int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
int main(){
    int a, b;
	while(~scanf("%d%d",&a,&b)){

        printf("%d\n",lcm(a,b));
	}
	return 0;
}

抱歉!评论已关闭.