1.更相减损术
#include <iostream>
#include <cmath>
using namespace std;
int main ()
{
int a,b,t;
cin >> a>> b;
while(a!=b)
{
t=abs(a-b);
a=b;
b=t;
}
cout << a << endl;
return 0;
}
2.辗转相除法
#include <iostream>
using namespace std;
#include <cmath>
int main ()
{
int a,b;
cin >>a >> b;
while(a%b!=0)
{
int t=a%b;
a=b;
b=t;
}
cout << b << endl;
return 0;
}