The bug is simple.

You do not calculate the least common multiple (LCM) of two numbers by multiplying both numbers with another 3rd number in the hopes that it will one day make them equal (it will not -- unless the 3rd number is 0 or infinity).

There are various ways to find the least common multiple. Here are some in this article.

Solve the problem: you can easily do this after you understand at least one algorithm for the least common multiple calculations. Take your best shot, try to solve the problem and share your solution if you need further assistance.

Good luck