The key observation is that the angle is used to calculate the initial horizontal and vertical speed components, vx and vy. But they also form a vector, (vx, vy) with magnitude equal to the speed, so are related by the formula
The condition that the missile hits the ground at range r can be put into the equations of motion to get
And the above formulae can be combined to eliminate vx and vy, forming a quadratic equation for t2, where t is the time of flight, which can then be easily solved to find the two values for t2
I've done yet another version of the ballistics app using the above mathematics, embedded below. It works the same way as before but uses new calculations as above.