If an (ideal) spring has been extended (from its equilibrium state, with no applied force on it) by a distance "x",
then the force needed to keep it in that position (with no net force upon it) must be exactly equal to the force exerted by the spring -- which is directly proportional to the distance "x".
If "k" is the spring-constant of this particular spring, then the force (in Newtons) is equal to: F = k x
Thus, we have: 40 N = (k)(5 cm) or k = 8 N / cm,
which means that every additional cm of extension will add 8 N to the force exerted by the spring.
¶ Therefore, the force necessary to keep the spring extended by 8cm would be 8/5 F = 64 N (i.e./, 3/5 greater than F).
When the spring is extended from 5cm to 8cm, the force increases (linearly) from 40 N to 64 N, with an AVERAGE force of 52 N applied over a distance of 3cm or 0.03 meters.
Since "work" is "force over a distance" the work performed is: (52 N)(0.03 m)
= 1.56 Kg m^2 / s^2 = 1.56 Joules.
¶ Note that this problem can also be solved by calculating the difference in energy; however (since the force increases linearly for a "ideal" spring), it is much easier to use the AVERAGE force and multiply it by the distance. However, for a non-ideal spring, the work is equal to the area under the curve (of force vs. distance), so some elementary calculus may be needed to calculate the integral.