Below is my first solution, but it is incorrect.
The mass of the bullet is m = 0.017kg.
Let the initial speed of the bullet is v.
The initial kinetic energy of the bullet is


.
The initial potential energy of the spring is U
0 = 0, and the final potential energy of the "spring + bullet" is

, where k = 100N/m, and x = 0.403m.
The final kinetic of the "spring + bullet" is Kf = 0.
Since the total mechanical energy is conserved, then we get
We must consider the conservation of momentum of the system! So my revised solution is:
The mass of the bullet is m = 0.017kg. The mass of the block is M = 0.401kg.
Let the initial speed of the bullet is v. Then the initial speed of the "bullet + block" is
The initial kinetic energy of the "bullet + block" is


.
The initial potential energy of the spring is U
0 = 0, and the final potential energy of the "block + bullet" is

, where k = 100N/m, and x = 0.403m.
The final kinetic of the "block + bullet" is Kf = 0.
Since the total mechanical energy is conserved, then we get
Note: Thanks for Anonymous's input(see below).