The key problem of statistical physics standing over one hundred years is how to exactly calculate the partition function (or free energy) of many-body interaction systems, which severely hinders application of the theory for realistic systems. Here we present a novel approach that works at least four orders faster than state-of-the-art algorithms to the problem and can be applied to predict thermal properties of large molecules or macroscopic condensed matters via emph{ab initio} calculations.The method was demonstrated by C$_{60}$ molecules, solid and liquid copper (up to $sim 600$GPa), solid argon, graphene and silicene on substrate, and the derived internal energy or pressure is in a good agreement with the results of vast molecular dynamics simulations in a temperature range up to $2500$K, achieving a precision at least one order higher than previous methods. And, for the first time, the realistic isochoric equation of state for solid argon was reproduced directly from the partition function.