1+(n-1)p+(n-2)p^2+(n-3)p^3+(n-4)p^4+.+2P^(n-2)+p^(n-1)
=1+n(p+p^2+p^3+...+p^(n-1))-p(1+2+3+...+(n-1))
=1+np(p^(n-1)-1)/(p-1)-pn(n-1)/2
=1+n(p^n-p)/(p-1)-pn(n-1)/2
1+(n-1)p+(n-2)p^2+(n-3)p^3+(n-4)p^4+.+2P^(n-2)+p^(n-1)
=1+n(p+p^2+p^3+...+p^(n-1))-p(1+2+3+...+(n-1))
=1+np(p^(n-1)-1)/(p-1)-pn(n-1)/2
=1+n(p^n-p)/(p-1)-pn(n-1)/2