10分钟一次性AC。
#include<iostream>
using namespace std;
int gcd(int a, int b)
{
int c=-1;
while(c!=0)
{
c=a%b;
if(c!=0)
{
a=b;
b=c;
}
}
return b;
}
int main()
{
//freopen("xxx.in","r",stdin);
//freopen("yyy.out","w",stdout);
int n,m;
cin >> n >> m;
cout << gcd(n,m);
//fclose(stdin);
//fclose(stdout);
return 0;
}