题解 | #尼科彻斯定理#
尼科彻斯定理
https://www.nowcoder.com/practice/dbace3a5b3c4480e86ee3277f3fe1e85
#include <bits/stdc++.h> using namespace std; int main() { int m; while (cin >> m) { // 注意 while 处理多个 case // a的立方 int a = m * m * m; vector<int> res; int y = 1; for (int i = 0;i < m;i++) { res.push_back(y); y += 2; } while (true) { // 对连续奇数求和 int sum = accumulate(res.begin(), res.end(), 0); if (sum != a) { // 求和的结果不匹配就增加所有连续奇数的值 for (int &e : res) { e += 2; } } else { break; } } for (int i = 0;i < res.size() - 1;i++) { cout << res.at(i) << "+"; } cout << res.at(res.size() - 1) << endl; } }