An exact calculation of the free energy in systems with separable interactions