蓝桥练习系统-历届试题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; }本来是自己写的求两个数的最大公约数,后来发现辗转相除法,就又写了一下刷一遍
相关文章推荐
- 蓝桥练习系统 历届试题 公式求值
- 蓝桥- 历届试题 2013-10-19 核桃的数量
- 蓝桥历届试题 核桃的数量
- 历届试题 核桃的数量
- 蓝桥杯-历届试题-核桃的数量(GCD算法永远不会过时!)
- 蓝桥杯-- 历届试题 核桃的数量 (gcd)
- 蓝桥杯 历届试题 核桃的数量 (最小公倍数)
- 蓝桥杯 历届试题 核桃的数量(水题,三个数的最小公倍数)
- 蓝桥杯 历届试题 核桃的数量
- 历届试题 核桃的数量
- 2016蓝桥杯历届试题——核桃的数量(最小公倍数)
- 蓝桥杯练习系统历届试题 带分数 dfs
- 蓝桥杯 历届试题 核桃的数量
- 蓝桥杯练习系统历届试题 翻硬币
- 历届试题 核桃的数量
- 1503142303-蓝桥杯-历届试题 核桃的数量
- 蓝桥杯练习系统历届试题 剪格子 dfs
- 蓝桥杯练习系统历届试题 买不到的数目
- 蓝桥杯:历届试题 核桃的数量【JAVA算法实现】
- 历届试题 核桃的数量 【水】