//求最大公约数
function max_divisor($a,$b)
{
<wbr><wbr><wbr> $n = min($a, $b);</wbr></wbr></wbr>
<wbr><wbr><wbr> for($i=$n; $i>1; $i--)</wbr></wbr></wbr>
<wbr><wbr><wbr> {</wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> if (is_int($a/$i)&&is_int($b/$i))</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> {</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> return $i; <wbr> //此</wbr></wbr></wbr></wbr></wbr></wbr>
处如果用echo $i;则输出结果为432;故应区分echo、return的区别
<wbr><wbr><wbr><wbr><wbr> }</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> }</wbr></wbr></wbr>
<wbr><wbr><wbr> return 1;</wbr></wbr></wbr>
}
//求最小公倍数
function <wbr> min_multiple($a, $b)</wbr>
{ <wbr></wbr>
<wbr>if($b==0) <wbr><wbr> //</wbr></wbr></wbr>
一定要考虑除数不能为零
<wbr><wbr><wbr> {</wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> return $b;</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> }else{</wbr></wbr></wbr>
<wbr><wbr><wbr> $m = max($a, $b);</wbr></wbr></wbr>
<wbr><wbr><wbr> $n = min($a, $b);</wbr></wbr></wbr>
<wbr><wbr><wbr> for($i=2; ; $i++)</wbr></wbr></wbr>
<wbr><wbr><wbr> {</wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> if (is_int($m*$i/$n))</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> {</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr><wbr><wbr> return $i;</wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> }</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> }</wbr></wbr></wbr>
}
<wbr><wbr><wbr> return $a*$b;</wbr></wbr></wbr>
}
//辗转相除法求最大公约数
<wbr>function max_divisor2($a, $b)</wbr>
{
<wbr><wbr><wbr> if($b==0)</wbr></wbr></wbr>
<wbr><wbr><wbr> {</wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> return $a;</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> }</wbr></wbr></wbr>
<wbr><wbr><wbr> else</wbr></wbr></wbr>
<wbr><wbr><wbr> {</wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> return max_divisor2($b,($a%$b));</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> }</wbr></wbr></wbr>
}
//加减法求最大公约数
function max_divisor3($a, $b)
{
<wbr><wbr><wbr> if ($a == $b)</wbr></wbr></wbr>
<wbr><wbr><wbr> {</wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> return $a;</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> }</wbr></wbr></wbr>
<wbr><wbr><wbr> elseif($a > $b)</wbr></wbr></wbr>
<wbr><wbr><wbr> {</wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> $a = $a-$b;</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> }</wbr></wbr></wbr>
<wbr><wbr><wbr> else</wbr></wbr></wbr>
<wbr><wbr><wbr> {</wbr></wbr></wbr>
<wbr><wbr><wbr><wbr><wbr> $b = $b-$a;</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr> }</wbr></wbr></wbr>
<wbr><wbr><wbr> return max_divisor3($a, $b);</wbr></wbr></wbr>
}