题解 | #整数和#
整数和
http://www.nowcoder.com/practice/bba8c89fddf7462e8c6aae4791b36e23
#include<stdio.h>
int main(){
int loop = 0;
scanf("%d",&loop);
while(loop--){
int x = 0,y = 0;
scanf("%d",&x);
int flag = 1;
if( x < 0 ){
flag = -1;
x *= -1;
}
y = (3*x)*(x+1)/2;
printf("%d\n",flag * y);
}
}