Force required to compress the spring is
.
Hooks law: .
Substitute and
.
.
Substitute in
.
.
The force required to compress the spring is
.
Work done by the object in moving from to
is
.
Find the work done in compress the spring .
The work done in compressing the spring is
.
The work done in compressing the spring is
.