-4

I know a and c. How can I find the least b if lcm(a,b) = c?

3 Answers3

0
a = m*d, b = n*d, d = gcd(a,b), so c = lcm(a,b) = mnd;  
Thus n = c/a. Notice that the less d, the less b.  
so we can traverse the factor d of a, such that gcd(a/d, n) = 1.
the least d is what we need, then b = n*d.
rsy56640
  • 299
  • 1
  • 3
  • 13
0

You can find the least common multiple using prime factorization. Here, lcm(a, b) has to contain all the prime factors of a and b in their highest multiple they appear in in any of the two numbers.

For example, 8 = 2^3 and 12 = 2^2 * 3, so lcm(8, 12) = 2^3 * 3 = 24.

This can easily be reversed: Find the prime factors of c (including their multiplicity), then check which ones already are covered by a. b has to be the product of the remaining ones.

So if c = 24 = 2^3 * 3 and a = 6 = 2 * 3, then b has to be 8 = 2^3. The 3^1 is already covered by a, but a only has 2^1, so b has to be 2^3.

tobias_k
  • 81,265
  • 12
  • 120
  • 179
0

If c is lcm(a, b), c%a=0

Then,

(gcd(a, c/a) * c) / a

gives the answer.

This follows from the fact that lcm(a,b) * gcd(a,b) = a * b

Also, gcd(a,b) is easily implemented through euclid's algo, which solves your problem in logarithmic-complexity.

vish4071
  • 5,135
  • 4
  • 35
  • 65