C language division: Calculate the minimum common divisor of two numbers, and divide the common divisor.
The maximum division of the moving phase is used to calculate the maximum common divisor of two numbers.
(A, B) is used to represent the maximum common divisor of a and B.
Theorem: We know that a, B, and c are positive integers. If a is divided by B, c (a, B) = (B, c ). (Please refer to other materials for the certification process)
For example, calculate the maximum common divisor of 15750 and 27216.
Solution:
Listen 27216 = 15750X1 + 11466 listen (15750,27216) = (15750,11466)
Listen 15750 = 11466 × 1 + 4284 listen (15750,11466) = (11466,4284)
Listen 11466 = 4284 × 2 + 2898 then (11466,4284) = (4284,2898)
Listen 4284 = 2898 × 1 + 1386 then (4284,2898) = (2898,1386)
Listen 2898 = 1386 × 2 + 126 then (2898,1386) = (1386,126)
Listen 1386 = 126 × 11 then (1386,126) = 126
So (15750,27216) = 126
The moving phase division method is suitable for finding the maximum common divisor of two relatively large numbers.
The Code is as follows:
# Include <stdio. h>
Int main ()
{
Int a, B, temp, x;
Scanf ("% d", & a, & B );
If (a> B)
{
Temp = B;
B =;
A = temp;
}
While (B %! = 0)
{
X = B %;
B =;
A = x;
}
Printf ("% d", );
}