The shorter leg of a right triangle is 8 centimeters less than the other leg. Find the length of the two legs if the hypotenuse is 40.