游客 Signup | Login
中文 | En

3834 - 第六章:函数的使用《练习5:求最大公约数gcd》

通过次数

0

提交次数

0

Time Limit : 1 秒 Memory Limit : 128 MB

【求最大公约数-辗转相除法】输入任一的自然数A, B, 求A , B的最大公约数。

输入:51 34
输出:17

include<cstdio>

using namespace std;

int gcd(int xx,int yy)
{
 if(xx==0) return yy;
 else return gcd(yy%xx,xx);
}
int main()
{
    int a,b,t;
    scanf("%d%d",&a,&b);
   
    printf("%d\n",gcd(a,b));
   
    return 0;
}

Input

Output

Examples

Input Format

34 51

Output Format

17