Ian gave you the classic lens equation, which is correct, but takes a little mathematical acrobatic to get to the answer of your question. I don't recognize Q.G.'s equation and actually think, there is something missing (-1), but I can offer this equation for the magnification 'm':
m = (v/f)-1 = f/(u-f)
where 'v' is the lens or bellows extension, 'u' is the lens to subject distance, and 'f' is the focal length.
I assume, you can solve those for 'u' and 'v', if not let me know.
By the way, if you intent to do more of this, check this out:
Dead Link Removed
and scroll down to 'Bellows Traget & Ruler'.