Principle of maximum common approx.

Source: Internet
Author: User
Tags greatest common divisor

 

Something summarized at some time last year, there was a question about "More evict skills" during this provincial competition. I feel that these small knowledge cannot be ignored. I will post it and share it with you ~

Phase Division

Division, also known as Euclidean (Euclid) Algorithm, which was proposed by Euclidean in 300 BC.

Follow these steps to calculate the maximum common divisor of two numbers using the moving phase division:

First use a small number to divide a large number and obtain the first remainder;

Use the first remainder to divide a small number and obtain the second remainder;

The second remainder is used to divide the first remainder, and the third remainder is obtained;

In this way, the remainder is removed from the last one until the remainder is 0. In this case, the last divisor is the maximum common divisor (if the last divisor is 1, the original two divisor is the mutual prime number ).

The moving phase division method is used to calculate the maximum common divisor of two numbers. If you want to calculate the maximum number of common dikes, You can first calculate the maximum common dikes of two numbers, and then calculate the maximum common dikes of the maximum common divisor and the third number. In this way, it goes down until the last number. The final largest common divisor is the maximum common divisor of a number.

The general mathematical formula of this idea can be expressed:
  Gcd (a, B) = gcd (B, A mod B)
Note: The gcd (x, y) function indicates the maximum common divisor of X and Y ,(Greatest common diviser); X mod y indicates the remainder of X except y, which can be expressed as X % Y in C;

It is simply described as follows: A and B are the largest common divisor, which is equal to the maximum common divisor of the remainder of B and A except B.

Sharing a great dealRefinedFunctions

Int gcd (int A, int B ){
While (A> B? (A = A % B) :( B = B % ));
Return A + B;
}

I also found someInteresting things~~

Minimum Public multiple

The formula can be described as follows:
  LCM (a, B) * gcd (a, B) = a * B
Note: The LCM (x, y) function represents the minimum public multiple of X and Y (Least Common multiply); The gcd (x, y) function indicates the maximum number of common appointments of X and Y;

By using this formula, we know that the minimum public multiples of A and B are required. You only need to obtain the maximum public divisor of A and B, and then apply the formula to obtain the minimum public multiples.

This formula is easy to understand.

Evict

In the early days of our country, we also had an algorithm for finding the largest common divisor, that is, the "more evict" technique. In the <Chapter 9 arithmetic>, there were more evict steps:

The number of the half-to-half sub-sets the denominator. Reduce the number of sub-sets by less, reduce the number of sub-sets, and seek for the sub-sets.

1. Any two positive integers are given; judge whether they are all even numbers. If yes, use 2 to reduce; if not, execute step 2.
2. subtract a smaller number from a larger number, then compare the difference between the smaller number and the obtained one, and reduce the number in an greater number. continue this operation until the obtained number is equal. Then, this number (equal number) is the maximum public approx.

I have seen that a exercise is described by the more evict technique. The general idea is as follows:

Dr. qhas trained a group of bacteria in the laboratory. he found two mutually restrictive bacteria, A and B. so he cultured the two bacteria. In the test, he found that bacteria A and B had the following rules: When AB bacteria coexist, bacteria, A party with a small quantity of data in B will swallow part of the individuals of a large number of parties every day, and the number of swallowed-UP members is equal to the number of individuals of a few Parties. This way, it will continue until, when the number of bacteria B is equal, they are no longer swallowed up.
The program requires that two numbers a and B be input to represent the numbers of bacteria A and B respectively. The program requires that the number of AB bacteria be output to the total number of stable bacteria.

In essence, this question requires the maximum public multiple of two numbers, but it is described using a more evict technique. If you are not familiar with the more evict technique, the first idea is to simulate the description of the question; once we see that it is the greatest common divisor, we can use the moving phase division to solve the problem, greatly improving the efficiency of solving the problem!

In mathematics, the method of separation and subtraction are used in mathematics.Essentially the sameIt is just a subtraction description and a division description. Obviously, the approximate speed of the moving phase division is much faster.

 

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.