训练1-V

输入2个正整数A,B,求A与B的最大公约数。

Input
2个数A,B,中间用空格隔开。(1<= A,B <= 10^9)
Output
输出A与B的最大公约数。
Sample Input
30 105
Sample Output
15
#include<stdio.h>                    //水题,用欧几里得算法
int main()
{
	int GCD(int a,int b);
	int A,B;
	scanf("%d%d",&A,&B);
	printf("%d\n",GCD(A,B));
	return 0;
}

int GCD(int a,int b)             //大家最好记住这个模板,不知道算法的可以百度
{
	return b==0?a:GCD(b,a%b);
}

...

posted @ 2018-06-05 17:50  浮生惘语  阅读(191)  评论(0编辑  收藏  举报