Accessing the speed of sound in relativistic ultracentral nucleus-nucleus collisions using the mean transverse momentum