I have a very peculiar problem.
I am interested to solve problems such as:
B>8 (first occurence of B>8) for 40*B = 15*D such that B and D are integer numbers.
The problem is also illustrated in the following image:

Given that the bottom (black) train of events runs at a certain rate and the top interval is also of a certain fixed periodicity, such that the number of black intervals per blue interval is an integral number, how then to choose the width of the green intervals such that their number is equal to or higher than a certain value and such that each green interval also contains an equal number of black intervals/events at t1. i.e. how to synchronize three periodic systems by adjusting 1.
The solution should be implementable as a function in a programming language (doesn't matter at this point).
I suspect that it has to do with prime numbers but I cannot put my finger on it (and I am no mathematician). This seems easy, but it is not :s
If you divide both sides by $15$ you get $D=\frac 83B$ Now you need the smallest $B$ that is both greater than $8$ and a multiple of $3$ (so $D$ will be an integer). That is $9$, so $B=9, D=24$
For your comment, the procedure is quite general. From $aB=bD$ you divide by $b$ to get $\frac abB=D$. Reduce $\frac ab$ to lowest terms, then $B$ has to be a multiple of whatever denominator is left. Find the smallest multiple of that which is greater than $x$ and you have your answer.