Given n and m find the smallest k such that:

n divides LCM(m,k) ; m divides LCM(n,k)

My Solution :


   (m==n) then k=1


   k = LCM(m,n) / GCD(m,n)

   If : k divides MIN(m,n) then k=MAX(m,n)

MIN(x,y) : Gives the minimum of x and y .

MAX(x,y) : Gives the maximum of x and y .

GCD(x,y) : Gives the Greatest Common Divisor of x and y .

LCM(x,y) : Gives the Least Common Multiple of x and y .

My solution gives wrong answer , Could anybody suggest me the correct answer ??

Suppose $n=p_1^{e_{n1}}p_2^{e_{n2}}p_3^{e_{n3}}\cdots$ and $m=p_1^{e_{m1}}p_2^{e_{m2}}p_3^{e_{m3}}\cdots$ then you need $k=p_1^{e_{k1}}p_2^{e_{k2}}p_3^{e_{k3}}\cdots$

where $e_{ki}=0$ when $e_{ni}=e_{mi}$ and $e_{ki}=\max(e_{ni},e_{mi})$ when $e_{ni}\not = e_{mi}$.

I cannot see an easy way of writing this.

As an example, if $n=360$ and $m=270$, I think the smallest $k$ is $216$ while your suggestion seems to give $12$.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.