An analytical formula for the range of ions in solids