Maximum common approx.

Source: Internet
Author: User
Perform the following steps to calculate the maximum common divisor of two numbers by moving phase division: first use a small number to divide a large number to obtain the first remainder, and then use the first remainder to divide a small number, the second remainder is obtained, and the second remainder is used to divide the first remainder, and the third remainder is obtained. In this way, the last remainder is removed until the remainder is 0. In this case, the last divisor is the maximum common divisor (if the last divisor is 1, the original two divisor is the mutual prime number ). For example, for the maximum number of 1515 and 600, the first time: with 600 except 1515, the merchant 2 more than 315; the second time: with 315 except 600, the merchant 1 more than 285; the third time: 285 in addition to 315, more than 1 30; fourth time: 30 in addition to 285, more than 9 15; fifth time: 15 in addition to 30, more than 2 0. The maximum number of public appointments between 1515 and 600 is 15.
Int gcd (int x, int y) {If (x <Y) int T = x, x = Y, y = T; return y = 0? X: gcd (Y, X % Y );}


Maximum common approx.

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.