In this paper we give unified formulas for the numbers of representations of positive integers as sums of four generalized m-gonal numbers, and as restricted sums of four squares under a linear condition, respectively. These formulas are given as Z-linear combinations of Hurwitz class numbers. As applications, we prove several Zhi-Wei Sun's conjectures. As by-products, we obtain formulas for expressing the Fourier coefficients of 19(7, z)4, 7/(7 )12, 7/(7)4 and 7/(7 )87/(27 )8 in terms of Hurwitz class numbers, respectively. The proof is based on the theory of Jacobi forms. (c) 2025 Elsevier Inc. All rights are reserved, including those for text and data mining, AI training, and similar technologies.