欧几里德算法求最大公约数
在求两个数的最大公约数方法中,
辗转相除法是比较快的一种方法。
也就是著名的欧几里德方法。
 View Code
View Code 
int Gcd(int a, int b){ return b==0?a:gcd(b, a%b); }
 View Code
View Code 
#include "iostream"
#include "cstdio"
#include "cstring"
#include "string"
#include "algorithm"
using namespace std;
int Gcd(int a, int b)//殴几里得算法,求最大公约数
{
if(b==0) return a;
else return Gcd(b, a%b);
}
int main()
{
int x, y;
while(cin>>x>>y)
{
cout<<Gcd(x, y)<<endl;
}
}
posted on 2012-04-05 16:48 More study needed. 阅读(204) 评论(0) 收藏 举报
 
                    
                     
                    
                 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号 
