`
ling凌yue月
  • 浏览: 333979 次
  • 性别: Icon_minigender_1
  • 来自: 郑州
社区版块
存档分类
最新评论

辗转相除求最大公因数(greatest common factor)欧几里得

    博客分类:
  • php
阅读更多

 

 

/**
 * 得到最大公因数
 *
 */
function getGreatestCommonFactor($a, $b){
	if($a < 0 || $b < 0){
		return false;
	}
	if($b > $a){
		return getGreatestCommonFactor($b, $a);
	}else{
		if($a % $b == 0){
			return $b;
		}else{
			return getGreatestCommonFactor($b, $a % $b);
		}
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics