GCD&EXGCD algorithm

Source: Internet
Author: User
Tags gcd greatest common divisor

Preface

For many number theory problems, it is necessary to involve GCD, solve gcd, and often use Euclidean algorithm.

For many solving problems, the Bézout equation can be listed: AX+BY=GCD (A, B), with the EXGCD solution to the answer, EXGCD is the expansion of Euclid algorithm.

Here's a little learning about the two algorithms

Content

Euclidean algorithm

  by Baidu Encyclopedia

Euclidean algorithm, also known as the greatest common divisor method, is used to calculate two positive integers, a, B.

From the division of integers can be seen: for any given two integers a,b0, there must be two integers q and R exist, make A=QB+R,0≤RB, and Q and R is the only existence, this is a fundamental theorem of number theory, a series of important properties of integers are derived from this, if repeated use of this fundamental theorem, can be obtained because each time division, the remainder is at least one, and B is a finite number of positive integers, so at most b times, you can always get a remainder is a zero equation, that is, rn+1=0.

Of course, Baidu said this kind of words I can not understand.

In fact, the GCD (A, B) =gcd (b,a MoD), until a≡0 (mod b) , B is the request.

The purpose of this method is to achieve a reduction in the number of two numbers that can be solved, making the efficiency a logarithmic level.

So, how do we prove the correctness of this formula?

We make

Depending on the definition of the modulo operation, there can be

  

  

GCD&EXGCD algorithm

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.