[Turn] The algorithm of seeking greatest common divisor

Source: Internet
Author: User
Tags gcd greatest common divisor

More subtractive loss Surgery

More subtractive damage, also known as "equivalence algorithm"

On the question of numerator, the essence is how to find the numerator, the denominator greatest common divisor. This method is described in the nine chapters of arithmetic, which is called "more subtractive subtraction", and the mathematician Liu Hui has made clear annotations and explanations to this method, which is a practical mathematical method.

Example: Today there are forty nine-ninety firsts, ask about the geometry?

We use (91,49) to represent the greatest common divisor of 91 and 49. According to Liu Hui, the numerator and denominator are listed separately.

"To reduce the number of, more subtract, and so on, and so on, and so on, and so on, and so on, that is, in addition to the same, so the subtraction of the overlap, so the number of the sum." ”

The translation is as follows:

The law of numerator is: if the numerator, denominator are even, can be removed first by 2, otherwise, the numerator and the denominator of the sequence in it, and then the number of large numbers, tossing and subtracting, seeking their greatest common divisor, with the greatest common divisor to reduce the numerator and the denominator.

It is the same as in the first proposition of vol. seven in the original geometry of the ancient Greek Euclid. The columns are as follows:

91 49

42 49

42 7

35 7

28 7

21 7

14 7

7 7

The 7 we get here is called "equals", and 91 and 49 are overlapping (that is, multiples) of such numbers, so 7 is the number of their conventions. The greatest common divisor 7 and 7 are 7, (7,7) = 7, so (91,49) = (42,7) = (7,7) =7

There is still a theoretical and practical value in the modern age. Professor Wu Wenjun said: "In our country, to seek two number greatest common divisor namely equal number, with the more subtractive loss of the technique, will be reduced by a small reduction of two, such as 24 and 15 of the number, its gradual impairment as shown in the following table: (24,15), (9,15) (9,6), (3,6) (3,3)

Each two-digit number has the same equal number as the first two numbers, and the value of two is gradually reduced, so it is necessary to obtain the same two numbers after a limited step, that is to ask for the same number, the reason is self-evident.

This method, which is not self-evident, is completely structural and mechanized, which can be programmed and implemented ". Mr Wu's remarks not only illustrate the theoretical value of the law, but also indicate the direction of study and study.

The more subtractive method is of great value, it lays down the theoretical basis of the asymptotic fraction, indefinite analysis, congruence theory and the theory of large-yan. Look, I can taste it carefully.

Euclidean method

The Euclidean algorithm (Euclidean algorithm) is an algorithm for finding the largest common factor of two positive integers. It is the oldest known algorithm and can be traced back to the first 300 years. It first appeared in Euclid's Geometry Original (vol. VII, Proposition I and II), while in China it dates back to the nine chapters of Arithmetic, which appeared in the Eastern Han Dynasty. It does not need to decompose the two-digit mass factor.

Prove:

Set two numbers to A, B (b

The Euclidean method uses the following properties to determine the maximum common factor of two positive integers a and B:

1. If R is the remainder of the a÷b, then gcd (A, B) =gcd (B,R)

The largest male factor of 2.a and its multiples is a.

Another way to do this is:

1.a÷b, so that R is the resulting remainder (0≤r

2. Swap: Place A←b,b←r and return to the first step.

An algorithm for solving greatest common divisor by C + +

The method of more subtractive loss

int gcd (int a,int b)

{

while (A!=B)

{

if (a>b)

A-=b;

Else

B-=a;

}

return A;

}

The method of dividing--recursion

int gcd (int a,int b)

{

if (b==0)

Returna;

Else

return gcd (B,A%B);

}

The method of dividing--pure cycle

int gcd (int a,int b)

{

int R;

while (b!=0)

{

R=a%b;

A=b;

B=r;

}

return A;

}

[Turn] The algorithm of seeking greatest common divisor

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.