How to solve distance formula?