Hooke's Law:
F = -kx
Where k is a constant and x is the distance that a spring is stretched from its rest position. If you hang a barbell from a spring, the force of gravity is pulling on the spring. The spring will stretch until the forces balance:
-kx = mg
Where m is the mass of the barbell and g is the acceleration due to gravity (-9.8 m/s2). For the 3 kg barbell:
-k(40) = (3 kg)*(-9.8 m/s2)
k = (3)*(9.8)/40 = 0.735
For a 5 kg barbell, then:
-kx = mg
-(0.735)*x = (5 kg)*(-9.8 m/s2)
x = (5)*(9.8)/(0.735) = 66.67 cm
You can also solve this by noting that since Hooke's Law is linear, the amount of stretching will be proportional to the weight of the barbell; that is a 5 kg weight will stretch the spring 5/3 as far as a 3 kg weight:
(3 kg)/(40 cm) = (5 kg)/x cm
x = (5/3)*40 = 66.67 cm