Expand Euclidean algorithm, point on a straight line

Source: Internet
Author: User
Tags gcd greatest common divisor

It's not very clear in the textbook about this section.

Part of the content is referenced from: http://www.cnblogs.com/frog112111/archive/2012/08/19/2646012.html

Extended Euclidean algorithm

Basic algorithm: For a non-negative integer A,B,GCD (A, B) that is not exactly 0, the greatest common divisor of A/b is bound to have an integer pair of x, Y, which makes gcd (A, b) =ax+by.

The application of the extended Euclidean algorithm mainly has the following three aspects:

(1) solving indefinite equation;

(2) solving the linear linear equation (congruence);

(3) The inverse element of the solution module;

(1):

Set A,b,c to any integer, G=GCD (A, b), the equation ax+by=g a set of solutions (X0,Y0), when C is a multiple of G, ax+by=c a group of solutions for (p0,q0) = (x0*c/g,y0*c/g), the other solution of the equation is (pi,qi) = (P0 + b/g * t,q0-a/g*t) where T is an arbitrary value, and when C is not a multiple of G, there is no solution

  

     void meuclid (int a, int b, int &d, int &x, int   &if(b==0) {d=a;x=1; y=0;  returnElse     {meuclid (b,a%b,d,y,x);        Y-=x* (A/b);    }}
View Code

Expand Euclidean algorithm, point on a straight line

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.