您的位置:首页 > 其它

蓝桥练习系统-历届试题01-核桃的数量

2014-11-27 21:51 281 查看
#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;
}
本来是自己写的求两个数的最大公约数,后来发现辗转相除法,就又写了一下刷一遍
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: