Lets dub the two numbers x and y
We can basically make a system of equations and solve from there!
x^2-y^2=320
x+y=40
x=40-y
(40-y)^2 - y^2=320
1600-80y+y^2-y^2=320
1600-80y=320
-80y=-1280
y=16
Now input y into the equation
x+y=40
x+16=40
x=24
x is 24, y is 16