maxCommonDivisor.php
function calMaxCommonDivisor($m, $n) {
if ( $m < $n ) {
$tmp = $m;
$m = $n;
$n = $tmp;
}
$r = $m % $n;
while ($r != 0) {
$m = $n;
$n = $r;
$r = $m % $n;
}
return $n;
}
if ( $argc != 3 ) {
exit;
}
$m = $argv[1];
$n = $argv[2];
echo calMaxCommonDivisor($m, $n), "\n";
网友评论