# The moving phase division is used to calculate the maximum common divisor and the least common multiple.

Source: Internet
Author: User

I. Moving Phase Division (EuclideanAlgorithm)

Definition: the so-called "moving phase division" refers to dividing the given two numbers by a large number by a small number. If the remainder is not zero, the remainder and a smaller number form a new pair. Continue the division until the large number is wiped out by decimal places, then, the smaller number is the largest common divisor of the original two numbers.

Ii. evict

(1) evict in chapter 9 arithmetic:

Half and half, not half, sub-sets the number of denominator and sub-, to reduce more, more to reduce, ask for it, and so on, to equal the number.

(2) In modern mathematics, evict:

Step 1: Specify any two positive integers and determine whether they are all even numbers. If yes, use 2 conciseness. If not, perform step 2.

Step 2: Use a larger number to reduce a smaller number, then compare the obtained difference with a smaller number, and then reduce the number in a larger number. Continue this operation until the obtained subtraction and difference are equal. Then, this equality number is the maximum common number.

2. Definition: the so-called evict operation is to subtract a small number from a large number for the given two numbers, then, the difference and the smaller number form a new pair of numbers. Then, the larger number is used to subtract the smaller number, and this step is executed repeatedly until the difference is equal to the smaller number, at this time, the two equal numbers are the maximum common divisor of the original two numbers.

Phase division algorithm:

` # Include <stdio. h> void main () {int X, Y, a; int T, R; printf ("input two numbers: \ n"); scanf ("% d ", & X, & Y); A = x * Y; If (x <Y) {T = x; X = y; y = T;} while (y! = 0) {r = x % Y; X = y; y = r;} printf ("maximum common divisor: % d \ n", X ); printf ("minimum public multiple: % d \ n", A/X );} `

Binary recursion:

` # Include <stdio. h> int main () {int A, B, C, G; int gcd (int A, int B); printf ("Please input two numbers \ n "); scanf ("% d", & A, & B); C = a * B; G = gcd (a, B); printf ("the maximum common divisor is: % d \ n minimum public multiple: % d \ n ", G, C/g);} int gcd (int A, int B) {If (B = 0) return A; else return gcd (B, A % B );} `

Why not judge the size of two numbers?

If a <B... then a % B = .. Therefore, gcd (B, A % B) = gcd (B, );

Related Keywords:

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.