This article mainly introduces PHP programming to find greatest common divisor and least common multiple methods, involving the mathematical calculation of PHP related arithmetic skills, the need for friends can refer to the next
Specific as follows:
Request greatest common divisor function max_pisor ($a, $b) { $n = min ($a, $b); for ($i = $n; $i >1; $i-) { if (is_int ($a/$i) &&is_int ($b/$i)) { return $i; If the echo $i is used here, then the output is 432; the difference between echo and return } } return 1;} Ask least common multiple function min_multiple ($a, $b) { if ($b ==0) //must consider divisor cannot be zero { return $b; } else{ $m = max ($a, $b); $n = min ($a, $b); for ($i =2;; $i + +) { if (is_int ($m * $i/$n)) { return $i; }}} return $a * $b;} The greatest common divisor function max_pisor2 ($a, $b) { if ($b ==0) { return $a; } else { return Max_pisor2 ($b, ($a% $b));} } Add and subtract greatest common divisor function Max_pisor3 ($a, $b) { if ($a = = $b) { return $a; } ElseIf ($a > $b) { $a = $a-$b; } else { $b = $b-$a; } Return Max_pisor3 ($a, $b);}
Related recommendations:
JS obtains least common multiple and the largest number of conventions
What is the maximum number of conventions for two integers?
2. Maximum number of conventions for M and N and least common multiple (maximum number of conventions : rotary-Rolling Division method)