Let `lambda=M//L`= mass per unit length of the chain and y is the length of the chain hanging over the edge. So the mass of the chain of length y will be `lambday` and the force acting on it due to gravity will be `mgy`.
The work done in pulling the `dy` length of the chain on the table.
`dW=F(-dy)` [dy is negative as y is decreasing]
As the chain is pulled slowly,
F=Weight of the hanging chain `=lambdayg`
i.e., `dW=(lambdayg)(-dy)`
So the work done in pulling the hanging portion on the table,
`W=-underset(L//n)overset0intlambdagydy=-lambdag[y^2/2]_(L//n)^0=(lambdagL^2)/(2n^2)=(MgL)/(2n^2)`
`[as lambda=M//L]`