题目描述
输入两个正整数,求其最大公约数。
输入
测试数据有多组,每组输入两个正整数。
输出
对于每组输入,请输出其最大公约数。
样例输入
49 14
样例输出
7
来源
#include<iostream>
#include<cstdio>
using namespace std;
//greatest common divisor
int gcd(int a,int b)
{
if(b==0) return a;
else return gcd(b,a%b);
}
int main()
{
int n,m;
while(scanf("%d %d",&n,&m)!=EOF)
{
printf("%d\n",gcd(n,m));
}
return 0;
}