At any position of the piston, say at a distance x from the bottom, net force on it is zero PA=Fext+mg+kx3∴P=Fext+mg+kx3∴ External work done by the gas isΔwgas=∫PdV=∫A(Fext+mg+kx3)Adx=L0∫L1Fextdx+mgL0∫L1dx+kL0∫L1x3dx=ΔWext+mg(L1−L0)+4K(L14−L04)=nRTln(L0L1)+mg(L1−L0)+4K(L14−L04)According to I law of thermodynamics for the gasΔQ=ΔU+ΔWgas=0+ΔWgas⇒ΔQ=ΔWgasΔQ=nRTln(L0L1)+mg(L1−L0)+4K(L14−L04)