Java, 67, 63 bytes
Golfed:
int x(int n,int p){return-((p%2<1)?p*p/2+p:p/2*(p+2)+1)+n-p*n;} Ungolfed:
int x(int n, int p) { return -((p%2<1) ? p*p/2+p : p/2 * (p+2) + 1) + n - p*n; } Basically I did some math on the formula. The n - p*n part takes care of the all n's in the formula. Then I used a super fun property of summing together linearly increasing set of integers (arithmetic series): I used the sum of first and last integer and then multiply it by set.length / 2 (I also check for the parity and handle it appropriately).