算法之【辗转相除法】

辗转相除法用于求两个或以上的正整数的最大公约数。

The Euclidean Algorithm is used to get the greatest common divisor.

语言描述:求两个整数的最大公约数时,先让一个整数整除另一个整数,求得余数,再分别将刚才的除数和余数作为新的被除数和除数进行运算,依次循环直到余数为0时停止,此时的除数就是刚开始两个数的最大公因子。用已求出的公因数和第三个整数再经过一次辗转相除法就求得三个数的最大公因数,以此类推。

Description:To find the greatest common divisor of two integers, firstly let one integerdivided by the other integer, the remainder is obtained, then regard the divisorand remainder as a new dividend and divisor respectively, and calculate again, until the final remainder is zero. Now the divisor is just the wanted greatest common divisor. Then compute the number along with a third integer through Euclidean Algorithm to get the greatest common divisor of three, and so on. 

C语言函数表达式:

C language description:

int fun(int a,int b) 

{

   int t;

while(b)

{

           t = a%b;

           a = b;

           b = t;

}

               return a;

}

转载于:https://my.oschina.net/jinhengyu/blog/1571839

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值