两个整数的最大公因数(Gcd)是同时取整除的最大整数.
#include<stdio.h>
unsigned int Gcd(unsigned int M,unsigned int N);
int main()
{unsigned int M=0,N=0;scanf("%d%d",&M,&N);printf("%d\n",Gcd(M,N));return 0;
}
unsigned int Gcd(unsigned int M,unsigned int N)
{unsigned int Rem;while(N>0){Rem=M%N;M=N;N=Rem;}return M;
}
input:
50 15
output:
5