Euclidean algorithm (divided) proof

Source: Internet
Author: User
Tags gcd greatest common divisor

After such a long time, finally know how to get along with the proof, before just remember, but not really understand, now write its proof, so that the next time you forget to look at. The greatest common divisor of a two-digit number is calculated.

To prove that the theorem is established, only the proof of gcd (A, b) = gcd (b, a% B) is required.

Proof: Make a% B = r, so a = K * B + R, so r = a-k * B, assuming that D is a number of conventions of a A, then D|a, d|b, (d|a means that D is evenly divisible A, that is, a can be divided by D), so A-k * B also must be divisible by D, that is D|r, d|. (a% B), so that D is also the number of conventions of B and (a% b), so that the number of conventions of a, B, and (A%B) is the same as the number of conventions, and their greatest common divisor must be the same, so gcd (A, b) = gcd (b, a% B);

So with this equation, basically even if the end, there is a step is how to find a specific number, when B equals 0 time can be, because the final recursive many or the original apartment number is the same, and finally there are 0, the two of their greatest common divisor is his own, that is, a, with the recursive code as follows

1 int gcd (intint  b)2{3      return0  ? A:GCD (b, a% b)); 4 }

Euclidean algorithm (divided) proof

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.