for a given v (velocity) and since g(the gravity) is constant then the only variable that will affect the range (distance in the x-direction) is sin(2theta) , and the max. number can be obtained from sin(2theta) is 1 (since the range for the sin is between -1 and 1) ..
then you will have sin(2theta) = 1 >> 2theta = arcsin(1) >> 2theta= 90 >> theta = 45 ..