Hi, IC gave you the basic formula, but didn't mention that magnification is proportional to p vs q.
Here's a calc'd example: say that you have a 2 inch wide negative which you want to enlarge to 40 inches wide, a 20x (linear) enlargement. This means the ratio of p/q must also be 20. That is, the lens to paper distance will be 20 times that of the lens to negative distance. The focal length of the lens determines what the exact distances will be.
Rather than try to do this in a proper math method, it's easier for me to simply set up a spreadsheet where I preset the focal length and q (lens to negative distance), then let the spreadsheet calculate p (lens to paper distance). Note: p = 1/(1/f - 1/q). I also have the spreadsheet display p/q. Then, I just keep adjusting the value of q until the ratio p/q =~20. Then, p + q = the negative to paper distance.
If we use an 80mm lens (there are 25.4 mm per inch, this is about 3.15 inches), it works out to p = 65.9 inches, and q = 3.31 inches. The neg to paper distance is, therefore, about 69 inches, a bit less than 6 feet. (A 75mm lens would only use 65 inches.)
In other sizes, enlarging a 1" wide neg (35mm film) to 40" width, using a 50mm lens, you'd need about 83 inch total distance, nearly 7 ft.
Or enlarging a 4" width (4x5 film) to 40" width, using a 150mm lens, you'd need about 71.5 inches.
Hope this helps. ps, I didn't double-check the calcs, so you might want to verify before building any walls. Note, too, that the measurement points should be from the nodal points of the lens, so it may be an inch or so off, depending on the lens.