AcWing 3558. 整数和
原题链接
简单
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int N = 1e3 + 10;
int t, n, m, k, l, r, op, x, y;
int f[N];
bool flag;
void solve() {
for (int i = 1; i < N; i++) {
f[i] += f[i - 1] + i;
}
cin >> t;
while (t--) {
flag = false;
cin >> n;
if(n<0){
flag = true;
n*=-1;
}
cout <<((f[2*n] - f[n - 1])*(flag?-1:1));
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}