A triangle is 180 degrees.
The rectangle has four 90 degree angles adding up to 360 degrees. Since the triangles are congruent each triangle has half as many degrees, namely 180. So this is true for any right triangle.
------------------------------------------------------------------
Add the whole numbers.
40 + 82 + x = 180
Subtract both sides by 122.
122 + x = 180
-122 -122
Gives you the third side to equal 58.
x = 58