Algorithm for Finding the maximum common approx.

Source: Internet
Author: User

Evict

Evict, also known as "equivalent algorithm"

The question about the denominator is actually how to find the largest denominator of the numerator. This method is introduced in chapter 9 arithmetic, which is called "More evict". The mathematician LIU Hui has made a clear note and explanation of this method, which is a practical mathematical method.

For example, if there are 49/91 today, what is the approximate ry?

We use () to represent the maximum appointment numbers of 91 and 49. According to Liu Hui, the numerator and denominator are listed respectively.

"By reducing less, reducing more, and asking for more information, the equal number is equal to, and the equal number is equal to, that is, the Division is also, and the equal number overlaps with each other, therefore, it is equal to the number."

The translation is as follows:

The principle of divisor is: if the numerator and denominator are even numbers, they can be divided by two first. Otherwise, the sequence of the numerator and denominator is located in it, and then the decimal number is reduced to a large number, calculate their maximum common approx. Use the maximum common approx.

It is the same as the first proposition in volume seven in the book geometric original by Euclidean Reid of ancient Greece. The column type is as follows:

91 49

42 49

42 7

35 7

28 7

21 7

14 7

7

In this example, 7 is called an equal number. 91 and 49 are the overlapping (multiples) of the equal number, so 7 is the approximate number. 7 and 7 have the largest common divisor of 7, () = 7, so () = 7

In the modern era, the evict technology still has theoretical and practical value. professor Wu Wenjun said: "in our country, we need to calculate the maximum common divisor of two numbers, that is, the equal number. We can use the more-dependent technique to reduce the two numbers, and then subtract them from each other to obtain them, for example, to calculate the equal number of 24 and 15, the gradual reduction is shown in the following table: (24, 15)-> (9, 15)-> (9, 6)-> (3, 6)-> (3)

The two numbers obtained each time have the same equal number as the first two numbers, and the value of the two numbers is gradually reduced. Therefore, after a finite step, the two numbers must be the same, that is, the expected equal number, the reason is self-evident.

This method is self-evident in computing. It is completely constructive and mechanized and can be compiled into a program for implementation ". mr. Wu's words not only illustrate the theoretical value of this method, but also specify the direction of learning and research.

The more-phase reduction method is of great research value. It lays the theoretical foundation for China's gradual score, indefinite analysis, the same-form theory, and the greater-derivative theory.

 

Phase Division

The moving phase division algorithm, also known as Euclidean algorithm, is an algorithm used to calculate the most common factor of two positive integers. It is the oldest known algorithm and can be traced back to the previous 300 s. It first appeared in Euclidean's ry (Volume VII, proposition I and II), while in China it can be traced back to the 9 Chapter arithmetic in the Eastern Han Dynasty. It does not need to separate binary numbers as quality factors.

Proof:

Set the numbers a and B (B <A) to calculate their maximum common divisor (a and B). The procedure is as follows: Divide A by B and A = BQ ...... r1 (0 ≤ r ). If R1 = 0, then (a, B) = B; If R1 = 0, then R1 is used to divide B, and B = r1q ...... r2 (0 ≤ R2 ). if r2 = 0, (a, B) = R1. If r2 = 0, R2 is used to divide R1 ,...... So on, until the Division can be completed. The last non-zero remainder is (a, B ).

The division of the moving phase determines the most common factor of two positive integers A and B using the following properties:

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

2. The most common factor of A and its multiples is.

Another method is:

1. A then B, so that r is the obtained remainder (0 ≤ r <B ). If r = 0, the algorithm ends. B is the answer.

2. Swap: Set A between B and B between R, and return the first step.

 

C/C ++ Algorithm for Finding the maximum Common Divisor

// Evict Method

Int gcd (int A, int B)

{

While (! = B)

{

If (A> B)

A-= B;

Else

B-=;

}

Return;

}

 

// Method of moving phase division-recursion

Int gcd (int A, int B)

{

If (B = 0)

Returna;

Else

Return gcd (B, A % B );

}

 

// Division of the Moving Phase-pure Loop

Int gcd (int A, int B)

{

Int R;

While (B! = 0)

{

R = A % B;

A = B;

B = R;

}

Return;

}

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.