#include<bits/stdc++.h>
using namespace std;
int a, b;
int main()
{
cin >> a >> b;
if (a == 0 || b == 0) return 0; // 一方为0,无最大公约数
if (a > b) swap (a, b); // 保证 a<b
while (b) swap (a = a % b, b); // 辗转相除法
cout << a << endl;
return 0;
}
原理讲解