#include#include int max_approximate(int num1, int num2){ if (num1 > num2) { int tmp = 0; tmp = num1; num1 = num2; num2 = tmp; } int min = num1; while (min) { if ((num2%min == 0)&&(num1%min==0)) { return min; } min--; } return 1;}int main(){ int num1 = 0; int num2 = 0; int ret = 0; scanf("%d%d", &num1,&num2); ret=max_approximate(num1, num2); printf("%d\n", ret); system("pause"); return 0;}
//辗转相除
int max_approximate(int num1, int num2)
{
if (num1 > num2)
{
int tmp = 0;tmp = num1;
num1 = num2;num2 = tmp;
}
int r = num2%num1;
while (r != 0)
{
num2 = num1;
num1 = r;r = num2%num1;
}
return num1;
}
int main()
{
int num1 = 0;
int num2 = 0;
int ret = 0;
scanf("%d%d", &num1, &num2);
ret = max_approximate(num1, num2);
printf("%d\n", ret);system("pause");
return 0;
}
//更相减损法:
int max_approximate(int num1, int num2)
{
if (num1 > num2)
{
int tmp = 0;
tmp = num1;
num1 = num2;
num2 = tmp;
}
int r = num2-num1;
while (r != num1)
{if (num1>r)
{
num2 = num1;
num1 = r;
}
else
{
num2 = r;
}
r = num2-num1;
}
return num1;
}
int main()
{
int num1 = 0;
int num2 = 0;
int ret = 0;
scanf("%d%d", &num1, &num2);
ret = max_approximate(num1, num2);
printf("%d\n", ret);
system("pause");
return 0;
}