Magnetic atoms can break the Cooper pairs of superconductors, leading to the formation of Yu-Shiba-Rusinov (YSR) bound states inside superconducting gaps. Theory predicts that the YSR bound states can be controlled by tuning the electron density at the Fermi energy, but it has not been studied deeply. In this work, we studied the nature of YSR bound states in response to the potential scattering U by tuning the electron density at the Fermi energy. By comparing two systems, Mn-phthalocyanine molecules on Pb(111) and Co atoms on PbSe/Pb(111), we demonstrate that the sign of U can be unambiguously determined by varying the electron density at the Fermi energy. We also show that U competes with the exchange interaction JS in the formation of YSR bound states. Our work provides insights into the interactions between magnetic atoms and superconductors at a fundamental level.