Extended Euclidean algorithm, bezout theorem and multiplicative inverse element

Source: Internet
Author: User
Tags gcd greatest common divisor

Extended Euclidean algorithm

The extended Euclidean algorithm (GCD) can find the solution of AX+BY=GCD (A, b) at the same time as the loss graph equation.

But how to beg? We observed gcd (A, b) =gcd (b, a%b), so set the following two equations:

Ax+by = GCD (A, b) = D;

BX ' + (a%b) y ' = gcd (b,a%b);

Obviously gcd (A, b) = gcd (b,a%b), which is Ax+by = bx ' + (a%b) y '.

In order to obtain X and Y, we need to ensure that a, B is unchanged, so: Ax+by = bx ' + (a%b) y ' = bx ' + (a-[a/b]*b) y '

=ay ' + b (x ' –[a/b]y ') ([A/b] indicates that the value of a/b is rounded down. )

So an identity relationship is available: x = y ', y = (x ' –[a/b]y '). in this way, a set of special solutions is obtained.

So how to perfection the solution? Give the recursive type directly:

x = x0 + (B/GCD) *t

y = y0– (A/GCD) *t

Obviously, B/GCD and A/GCD are mutual, which means that their gcd is 1. If they are divided by a value, some solutions may not be integers.

Bezout theorem

Do you have any eggs? In fact, it is possible to find the linear drop graph equation (indefinite equation).

For any integers a, B, and their greatest common divisor d, the linear graph-loss equation (called the Bezout equation) for unknowns x and y:

Ax + by = m

There is a solution if and only if M is a multiple of d. Because AX+BY=GCD (A, B). If M is not an integer multiple of D, then M is not an integer. The a,b,x,y are integers because they are lost graph equations. M is not an integer when the equation has no solution.

Bezout equation has a solution when there must be infinitely many integer solutions, each set of solutions x, y are called bezout number, can be obtained by expanding O. Just multiply X and y together by M/GCD (A, B).

In particular, the equation ax + by = 1 has a solution when and only if the integers a and B are interdependent. (Because GCD (A, b) =1)

Multiplication Inverse element

Given a ax≡1 (mod m) equation for x, x is the multiplicative inverse of a about m.

How can I ask for it? We equate it with: Ax mode m = 1 mod m = 1,ax=m (-y) +1,ax+my=1.

In other words, only the solution of the Ax+my=1 equation is required. Is it a little familiar? Yes, Pei the X, y with the expanded o+.

(Note to meet gcd (a,m) =1)

But obviously, a topic out to you can not let you output countless solutions, general solution is not realistic, is generally let you find the smallest x positive integer solution. What about that?

The general solution of X is X0+m/gcd*t, gcd=1 in the case of multiplicative inverse, so do not consider. So the general solution of X is X0+MT.

Because the general solution is X0+MT, the interval of the obvious smallest positive integer solution is [0,m], so it seems as if x0%m can find the smallest solution.

But what if x0%m is negative? The answer is to take the absolute value as well. (I don't know why)

Paste the following code: (To be more)

Extended Euclidean algorithm, bezout theorem and multiplicative inverse element

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.