Achieving a target least common multiple Recently I have faced the following problem.
I'm given three integers $a$, $b$ and $L$ where $\mathrm{LCM}(a,b,c)=L$ and $c$ is another integer.
It is worthy of mentioning that the value of $c$ will be smallest i.e if there are many possible values of $c$ then we have to choose the one which is smallest.
I myself solved this problem partially using
$$LCM(a,b,c)=LCM(LCM(a,b),c)=L\,,$$
suggesting
$$c = L/\mathrm{LCM}(a,b)\,.$$
This works for some cases. For example, if $a=3$, $b=5$ and $L=30$, then $c=2$ and my above equation gives the correct result.
But there are some cases for which my equation does't work. For example, if $a=10$, $b=15$ and $L=600$ then the correct value of $c$ is $200$ but my equation gives $c=20$.
How can I get correct result for the given second case for which my equation doesn't work? 
 A: Realize that $\text{lcm}(a,b,c) = \frac{abc}{\gcd(ab,bc,ac)}$, which can be seen by writing prime decompositions and noting that $$i+j+k-\text{min}
(i+j,j+k,i+k)=\text{max}(i,j,k)\,.$$
Then $$c = \frac{L}{ab} \gcd(ab,bc,ac)$$ and $$\gcd(ab,bc,ac) = \gcd(ab,\gcd(bc,ac)) = \gcd(ab, c\cdot\gcd(a,b)) = \gcd(a,b) \cdot \gcd\left(\frac{ab}{\gcd(a,b)}, c\right)$$
Therefore,
$$c =\frac{L}{ab}\gcd(a,b)\cdot\gcd\left(\frac{ab}{\gcd(a,b)},c\right) =  \frac{L}{\text{lcm}(a,b)}\gcd(\text{lcm}(a,b),c)$$.
Thus, $c$ is minimized when $\gcd(\text{lcm}(a,b),c)$ is minimized. As you note, this $\gcd$ can occasionally be 1 but not always.
Thus we want $c = k\frac{L}{\text{lcm}(a,b)}$ for some integer $k$, but note that the issue arises because, for all possible choices of $k$, $$\gcd\left(\text{lcm}(a,b),k\frac{L}{\text{lcm}(a,b)}\right) \ge \gcd\left(\text{lcm}(a,b),\frac{L}{\text{lcm}(a,b)}\right)$$ which may be greater than 1, and in fact $\gcd(\text{lcm}(a,b),c)$ is minimized when: $$\gcd\left(\text{lcm}(a,b),k\frac{L}{\text{lcm}(a,b)}\right) = \gcd\left(\text{lcm}(a,b),\frac{L}{\text{lcm}(a,b)}\right)$$ and note that this equality is always true when $k = \gcd\left(\text{lcm}(a,b),\frac{L}{\text{lcm}(a,b)}\right)$.
Therefore, $c = \frac{L}{\text{lcm}(a,b)}\gcd\left(\text{lcm}(a,b),\frac{L}{\text{lcm}(a,b)}\right)$ will always be a minimum and notably can be computed in polynomial time.
