#include <iostream>
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
using namespace std;
int Get(int a,int b){
int temp1,temp2,temp=0;
int res;
res = a*b;
temp1 = a>b?a:b;
temp2 = a>b?b:a;
/* 这是我自己写的求最大公约数的算法
for(int i=1;i<=temp2;i++){
if(temp2%i==0&&temp1%i==0){
temp = i;
}
}
*/
temp = temp1%temp2;
if(temp!=0){
while(temp!=0){
temp1 = temp2;
temp2 = temp;
temp = temp1%temp2;
}
}
temp = temp2;
// cout<<temp<<endl;
// getchar();
return res/temp;
}
int main(int argc, char** argv) {
int a,b,c;
int res;
cin>>a>>b>>c;
res = Get(Get(a,b),c);
cout<<res<<endl;
return 0;
}
本来是自己写的求两个数的最大公约数,后来发现辗转相除法,就又写了一下刷一遍
蓝桥练习系统-历届试题01-核桃的数量
最新推荐文章于 2018-12-04 13:17:46 发布