Winter training --GCD (greatest common divisor), LCM (least common multiple)

Each topic has a hyperlink, click to jump to the title screen! ! !

The greatest common divisor and least common multiple

1.c ++ comes __gcd (int m, int n) function can be used to greatest common divisor;
2. least common multiple = m * n / a greatest common divisor;

Here Insert Picture Description
Further greatest common divisor of two methods
M1. Euclidean (Euclidean algorithm)

Here Insert Picture Description
M2. Euclidean subtractor (Decreases Technique)
Here Insert Picture Description

See also the GCD

Pure violence enumeration can do
Here Insert Picture Description

The greatest common divisor multiple numbers

Here Insert Picture Description

Least common multiple of the number of

First seek the greatest common divisor of two numbers, then find the least common multiple of two numbers according to the greatest common divisor of two numbers, and then seek the least common multiple and greatest common divisor another new number, then the maximum seek common divisor least common multiple, and so on ......
Here Insert Picture Description

LCM&GCD

Suppose gcd (a, b) = x , lcm (a, b) = y, can be obtained: GCD LCM A = B, i.e., X Y = A B, with the dividing x2, have y / x = (a / x ) (B / X), so that y1 = y / x, a1 = a / x, b1 = b / x, then A1 = Y1 B1, and a1∈ [1, y1]. After this simplification, then traverse [1, sqrt (y1)] (only to traverse to the root number y1) to find satisfying gcd (a1, b1) == 1, the update answers.
Special attention sentence a1 * a1 = y case, the answer +1; otherwise answer +2.

NOTE:
1.gcd (A, B) = X, LCM (A, B) can be introduced Y = A B X = Y; but the reverse is not introduced;
2. The least common multiple of the greatest common divisor must be;
3. it is equal to the number of number gcd (a, b) established with gcd (a / x, b / x) a;
4.gcd (a, B) X is = GCD (m a, m B) = m * X; gcd (a / m, b / m) = x / m;

Here Insert Picture Description

Cute gcd

Here Insert Picture Description
Here Insert Picture Description

Takagi students factor

First seek the greatest common divisor of two numbers, and then seek the greatest common divisor of all factors, that is, all factors of two numbers.
Here Insert Picture Description

Published 11 original articles · won praise 12 · views 556

Guess you like

Origin blog.csdn.net/SSnTi/article/details/104244510