Seeking greatest common divisor PHP by the method of dividing

Source: Internet
Author: User
Tags greatest common divisor

<?php

/*

The process of the Euclidean method

Divide two numbers to take the remainder to determine whether the remainder is zero,

is zero, the divisor is the current greatest common divisor,

is nonzero, the current divisor becomes dividend and the remainder becomes a divisor,

Then divide and take the remainder, then judge, until the residue is zero.

12 8

12% 8 more than 4

8% 4 more than 0

4 for greatest common divisor.

*/

$m = Isset ($_request[' m ')? $_request[' m ']: 12;

$n = isset ($_request[' n ')? $_request[' n ']: 4;

$num 1 = $m;

$num 2 = $n;

bo=

$mod = $m% $n;

$m = $n;

$n = $mod;

}while ($mod! = 0);

echo "$num 1, $num 2 of greatest common divisor is: $m";


This article is from the "Linux Warden" blog, so be sure to keep this source http://sswqzx.blog.51cto.com/2494644/1962393

Seeking greatest common divisor PHP by the method of dividing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.