D[Sum[(x-k)^2,{k,1,n}],x]