最大公约数 | ||
| ||
description | ||
给定两个正整数a和b,你的任务就是求它们的最大公约数,a和b的范围均在long long内。
| ||
input | ||
输入数据有多组,每组1行,分别是a和b。
| ||
output | ||
输出一个数,即a和b的最大公约数。
| ||
sample_input | ||
12 4
30 12
| ||
sample_output | ||
4
6
|
#include <stdio.h>
#include <stdlib.h>
main()
{
long long a,b;
while(scanf("%lld%lld",&a,&b)!=EOF)
{
long long r;
r=a%b;
while(r)
{
a=b;
b=r;
r=a%b;
}
printf("%lld\n",b);
}
return 0;
}