Say you have $n$ planets orbiting around the sun, where the $i$th planet takes $t_i\in\mathbb{R}_{>0}$ days to complete one full cycle. Assume at $t=0$, all the planets are aligned with the sun. What is the minimum amount of time $T$ until all the planets are once again aligned with the sun? Does the answer always exist if the $t_i$'s are arbitrary real numbers? Or do they have to be rational?
If it's not clear, you can assume all the planets are points, and all orbiting in the same plane. And I want $T$ to be expressed as a function of $t_1, \ldots, t_n$. Lastly, "aligned" means that all the points are on the same side of the sun and form a straight line with the sun. (Though, for bonus points, you can also consider the case where the planets form a line being on either side of the sun)
To be mathematically precise, find the smallest $T$ such that $\frac{T}{t_i} \pmod{1}$ is the same for $i=1,\ldots,n$, where "mod" means "remainder" in this context. (e.g. 1.4 mod 1 = 0.4)
And just as a simple example for $n=2$, say that $t_1 = \pi$, and $t_2 = e$, then the minimal $T$ will be $\frac{e \pi}{\pi - e}\approx 20.17$.
Another simple example is for $t_1=\frac{2}{3}$,$t_2=\frac{3}{2}$, and $t_3=\frac{3}{7}$, In that case, the minimal $T$ will be $\frac{6}{5}$
I think I've found a solution, though it's not exactly closed form, and is more algorithmic. WLOG, assume $t_1<t_2<\ldots<t_n$. Also, assume that the periods are rational. Therefore, each period can be written as $t_i = \frac{N_i}{D_i}$, where $N_i$ and $D_i$ are integers. Technically, the periods are all allowed to share a single common irrational factor, but you can divide that out (and multiply it back in at the end).
The answer is as follows:
Begin the following loop
I'm pretty sure this will give an accurate answer. Note that every step is efficient, so the answer can be compute in $O(n)$ time.
My only wish is: does anyone have an elegant closed form expression answer, as opposed to my more algorithmic answer?
Also, as just an insight: note that Step #3 is the crucial computation step. For most large numbers, $k$ will be something large, and very often be set to $D$ (because it's hard to line up several planets exactly). If you want a more approximate or numerically stable answer (e.g. to use with floating point numbers), then when computing $k$, feel free to fudge this around a bit. Personally, I would use continued fractions to find an approximate solution with decent accuracy.