  In statistical mechanics, for a system with fixed number of particles, e.g.,
a finite-size system, strictly speaking, the thermodynamic quantity needs to be
calculated in the canonical ensemble. Nevertheless, the calculation of the
canonical partition function is difficult.\textbf{ }In this paper, based on the
mathematical theory of the symmetric function, we suggest a method for the
calculation of the canonical partition function of\ ideal quantum gases,
including ideal Bose, Fermi, and Gentile gases. Moreover, we express the
canonical partition functions of interacting classical and quantum gases given
by the classical and quantum cluster expansion methods in terms of the Bell
polynomial in mathematics. The virial coefficients of ideal Bose, Fermi, and
Gentile gases is calculated from the exact canonical partition function. The
virial coefficients of interacting classical and quantum gases is calculated
from the canonical partition function by using the expansion of the Bell
polynomial, rather than calculated from the grand canonical potential.
