We demonstrate that certain class of infinite sums can be calculated analytically starting from a specific quantum mechanical problem and using principles of quantum mechanics. For simplicity we illustrate the method by exploring the problem of a particle in a box. Twofold calculation of the mean value of energy for the polynomial wave function inside the well yields even argument $p$ ($p>2$) of Riemann zeta and related functions. This method can be applied to a wide class of exactly solvable quantum mechanical problems which may lead to different infinite sums. Besides, the analysis performed here provides deeper understanding of superposition principle and presents useful exercise for physics students.