百度百科:
分析:
证明了a,b的公约数们, 与 a,a mod b 的公约数们是相等的集合
则需要证明两个方向
c++实现:
#include <iostream>
#include <stdio.h>
#include <string>
#include <typeinfo>
#include <stack>
#include <vector>
#include <sstream>
#include <string.h>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
using namespace std;
typedef long long LL;
//递归
int gcd1(int a,int b){
return b==0?a:gcd1(b,a%b);
}
//循环
int gcd2(int a,int b){
int temp=0;
while(a%b!=0){
temp = a%b;
a = b;
b = temp;
}
return b;
}
int main()
{
cout<<gcd1(18,12)<<endl;
cout<<gcd2(18,12)<<endl;
return 0;
}