题解 | 尼科彻斯定理

尼科彻斯定理

https://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85

#include<iostream>
#include<string>
using namespace std;

int main() {
    int m;
    while (cin >> m) {
        int odd = m * m - (m - 1); //根据公式获取起点奇数
        cout << odd;
        for (int i = 1; i < m; i++) //遍历后续m-1个奇数
            cout << '+' << odd + 2 * i; //输出
        cout << endl;
    }
    return 0;
}

全部评论

相关推荐

脑袋锈住了:你这算啥,哥们中科院中强所硕士,本科211,叫我去干分拣,时薪20
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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