Well... You have:
D - distance to target
g = 9.8 - g- force
v - your firing velocity
Your velocity along X is v*cos(a)
Your velocity along Y is v*sin(a)
you need to travel distance D, hence your time of flight is
t = D/v*cos(a)
in that time you need to reach the maximum height of your flight and fall back. At maximum point your vertical speed will be 0, at the end of flight your vertical speed will equal to the starting vertical speed, if we ignore the air resistance.
So, bearing in mind that the equation for speed is v = acc*t (where acc is g for you) t = v/acc. In your case you have to drop speed to 0 and get it back to original, so you have factor of 2.
t = 2*(v*sin(a)/g)
Lets sum it up:
t = D/v*cos(a)
t = 2*(v*sin(a)/g)
2*(vsin(a)/g) = D/vcos(a)
You know everything but angle a.
So, by doing some variable transfers you get
2sin(a)cos(a) = Dg / v^2
which is:
sin(2a) = D*g/v^2
2a = arcsin( D*g/ v^2)
So, this must be the answer.
a = arcsin( D * g / (v^2) ) / 2