假设两个数字 63 14
那么他们的做法是
63-14=49
49 14
49-14=35
35 14
35-14=21
21 14
14-7=7
7 0
(a,b)和(b,a mod b)的公约数是一样的
得到他们的最大公约数=7
#include <bits/stdc++.h>
using namespace std;
void gcd(int a,int b)
{
while(b)
{
printf("a===%d b==%d\n",a,b);
int c=a%b;
a=b;
b=c;
}
cout<<a<<endl;
}
int main()
{
int a,b;
cin>>a>>b;
gcd(a,b);
return 0;
}