题解 | 整数和

整数和

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;
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务