How long time does it take before three planets achieve the same relative position?
The answer is never, except for the case when their orbital periods can be expressed with low integers, like the 4:2:1 resonance of Io, Europa and Ganymede
However, what you are asking about is when they are going to be in almost the same position again, a quazi-period.
To find those periods, we are pretty much only left by brute forcing as our method. A nice little detail about the case with three planets is that the inner planet is always aligned with one of the other ones at the closest three-planet alignments. That allows us to calculate accurate solutions. In the cases of four or even five planets I simply give up.
To check all the possibilities, we can use a program. Here is an example of a function in JavaScript returning a list of quazi-periods and alignment error:
sameLine = function (period1,period2,period3,limit){
results = [];
newMargin = 1;
synodic1 = 1/(1/period1 - 1/period2);
anomaly1 = (synodic1/period1) % 1;
synodic2 = 1/(1/period1 - 1/period3);
anomaly2 = (synodic2/period1) % 1;
alert(synodic1+","+synodic2);
for (i = synodic2; i < limit; i+=synodic2){
numb1 = i/synodic1 - (i/synodic1) % 1;
numb2 = i/synodic2 - (i/synodic2) % 1;
err1 = Math.abs((numb1 * anomaly1 - numb1 * synodic1/period3) % 1);
err2 = Math.abs((numb2 * anomaly2 - numb2 * synodic2/period2) % 1);
if (err1 > 1 - err1){
err1 = 1 - err1;
};
if (err2 > 1 - err2){
err2 = 1 - err2;
};
if ((err1 < newMargin) && (numb1 > 0)){
results.push([numb1 * synodic1,err1]);
newMargin = err1;
};
if ((err2 < newMargin) && (numb2 > 0)){
results.push([numb2 * synodic2,err2]);
newMargin = err2;
};
};
return results;
};
For Jupiter, Saturn and Uranus, I get the following output:
Time,,,error
13.81170069444156,,,0.30449020900657225
39.71676854387252,,,0.12441143762575813
41.43510208332468,,,0.08652937298028318
139.00868990355383,,,0.06455996830984656
138.1170069444156,,,0.04490209006572288
179.55210902774027,,,0.041627282914560304
317.6691159721559,,,0.0032748071511630172
3991.581500693611,,,0.002329597100612091
4309.250616665767,,,0.0009452100505313865
The first of this periods is of no use, as the error in alignment is almost a third of an orbit. Note that the one you found (that is really impressive you did,actually) gives an error in the alignment of less than a percent. We have to look at periods more than a thousand years long to find any better alignment.
Be sure to feed this function with accurate orbital periods.