Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
146106 石水生 完美立方 C++ Accepted 6 MS 276 KB 1363 2026-01-26 09:50:01

Tests(10/10):


Code:

#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int N; cin >> N; // 预计算立方值 vector<long long> cubes(N + 1); for (int i = 1; i <= N; i++) { cubes[i] = 1LL * i * i * i; } // 存储所有结果 struct Result { int a, b, c, d; bool operator<(const Result& other) const { if (a != other.a) return a < other.a; if (b != other.b) return b < other.b; if (c != other.c) return c < other.c; return d < other.d; } }; vector<Result> results; // 枚举所有可能的组合 for (int a = 6; a <= N; a++) { for (int b = 2; b < a; b++) { for (int c = b; c < a; c++) { for (int d = c; d < a; d++) { if (cubes[a] == cubes[b] + cubes[c] + cubes[d]) { results.push_back({a, b, c, d}); } } } } } // 按要求的顺序排序 sort(results.begin(), results.end()); // 输出结果 for (const auto& res : results) { cout << "Cube = " << res.a << ", Triple = (" << res.b << "," << res.c << "," << res.d << ")" << endl; } return 0; }