题解 | 整数和
整数和
https://www.nowcoder.com/practice/bba8c89fddf7462e8c6aae4791b36e23
#include <iostream>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int m;
while(cin >> m){
int N;
for(int i = 0; i < m; i++){
cin >> N;
if(N < 0){
N = -N;
cout << -3 * N * (N + 1) / 2 << "\n";
}
else cout << 3 * N * (N + 1) / 2 << "\n";
}
}
return 0;
}
查看17道真题和解析