GCD (A, B) is the greatest common divisor of A and B
LCM (A, b), which is the least common multiple of a and B
And then there's a formula.
A*b = gcd * LCM (GCD is gcd (A, B), (?∀?) shorthand do you understand?)
Explain (skip if you don't want to see) {
First, ask for a gcd, then ...
A/GCD and B/GCD These two numbers coprime, namely gcd (A/GCD, B/GCD) = 1, then ...
LCM = gcd * (A/GCD) * (B/GCD)
LCM = (A * b)/GCD
So.. A*b = GCD * LCM
}
So request LCM, ask GCD first
Spicy, the problem, gcd how to Beg
Euclidean method
While loop
1 ll GCD (ll A, ll b) {2 ll t; 3 while (b) {4 t = b; 5 b = a% b; 6 A = t; 7 }8 return A; 9 }
and a recursive notation.
1 ll GCD (ll A, ll b) {2 if(b = =0)returnA;3 Else returnGCD (b, a%b);4 }5 6 ll GCD (ll A, ll b) {7 returnB? GCD (b, a%b): A;8 }9 //two kinds are available
Spicy, LCM = A * B/GCD
(Note that this may be wrong, because A * b may be too large to exceed int or exceed Longlong)
So the recommendation is written as: LCM = A/GCD * b
And then a few formulas to prove it yourself.
GCD (ka, KB) = k * GCD (A, B)
LCM (ka, KB) = k * LCM (A, B)
Last time I hit this formula.
LCM (s/a, s/b) = S/GCD (A, B)
S = 9,a = 4,b = 6, fractional does not LCM, had to retain fractional form to-pass numerator.
When I see the formula on the right ....
(╯°д°) ╯┻━┻
This TM I think of, to prove to me is a certificate. t_t
ACM number Theory Tour 3---Greatest common divisor gcd and least common multiple LCM (struck, rebuild ( ̄? ̄))