HDU2.1.1 最小公倍數

  最小公倍數就是(a*b/最大公因數)

最大公因數採用輾轉相除法。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#define maxn 1050
using namespace std;
int a[maxn];
struct Node{
	int x;
	int y;
	double d;
	bool operator <(const Node &other) const{
		return d>other.d;
	}
}node[maxn];
int sum[maxn];
double dou[maxn];
string s,b;
//bool compare(const double &a,const double &b){
//	return a<b;
//}
int gcf(int a,int b){
	int temp=0;
	if(a<b){
		temp=b;
		b=a;
		a=temp;
	} 
	while(a%b!=0){
		temp=a%b;
		a=b;
		b=temp;
	}
	return b;
}
int lcm(int a,int b){
	int temp=gcf(a,b);
	return (a*b/temp);
} 
int main(){
	int n,m=0,index;
	int a1,b1,c1;
	double count=0;
	int t,cnt=0;
	while(cin>>m>>n){
		cout<<lcm(m,n)<<endl;
	}
	return 0;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章