标签:inf 垃圾 include code 语言 相对 class 大于 printf
#include <stdio.h>
int main(void)
{
int a = 0, b = 0, cnt = 0, min = 0, max = 0, sub = 1;
scanf("%d%d", &a, &b);
while(!(a & 0x1) && !(b & 0x1))
{
a = a >> 1;
b = b >> 1;
cnt++;
}
while(min != sub)
{
max = a > b ? a : b;
min = a > b ? b : a;
sub = max - min;
a = sub;
b = min;
}
while(cnt--)
sub = sub << 1;
printf("%d\n", sub);
return 0;
}
#include <stdio.h>
int main(void)
{
int a = 0, b = 0, mod = 1;
scanf("%d%d", &a, &b);
while(mod)
{
mod = a % b;
a = b;
b = mod;
}
printf("%d\n", a);
return 0;
}
从上面的代码部分可以看到更相减损术所需的的代码量要大于辗转相除法(或许是我写得太垃圾),而且更相减损术遇到两个数相差较大时需要进行更多步计算,相对来说辗转相除法不仅代码简洁,而且效率也更高。
标签:inf 垃圾 include code 语言 相对 class 大于 printf
原文地址:https://www.cnblogs.com/yutsnedge/p/14788115.html