some programs!!
This commit is contained in:
1 parent
ed054247d5
commit
71f1022dea
38 files changed
+1037
-281
No files matched your search
@@ -0,0 +1,54 @@
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
struct PerfectCubeNumber {
|
||||
int num = 0;
|
||||
std::tuple<int, int, int> children;
|
||||
|
||||
constexpr bool operator<(const PerfectCubeNumber& other) const {
|
||||
return std::tie(num, children) < std::tie(other.num, other.children);
|
||||
}
|
||||
};
|
||||
|
||||
constexpr int MAX_N = 101;
|
||||
std::vector<PerfectCubeNumber> perfect_cube_numbers;
|
||||
int n;
|
||||
|
||||
constexpr int cubes_sum(int a, int b, int c) {
|
||||
return a * a * a + b * b * b + c * c * c;
|
||||
}
|
||||
|
||||
void init_numbers() {
|
||||
for (int a = 2; a < MAX_N; a++) {
|
||||
for (int b = a; b < MAX_N; b++) {
|
||||
for (int c = b; ; c++) {
|
||||
const int x_cube = cubes_sum(a, b, c);
|
||||
if (x_cube > MAX_N * MAX_N * MAX_N) { break; }
|
||||
for (int x = std::floor(std::cbrt(x_cube)), i = 0; i < 3; x++, i++) {
|
||||
if (x * x * x == x_cube) {
|
||||
perfect_cube_numbers.push_back({x, std::tuple(a, b, c)});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
std::sort(perfect_cube_numbers.begin(), perfect_cube_numbers.end());
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
std::cin.tie(nullptr);
|
||||
|
||||
init_numbers();
|
||||
|
||||
std::cin >> n;
|
||||
for (const auto [num, children] : perfect_cube_numbers) {
|
||||
if (num > n) { break; }
|
||||
auto [a,b,c] = children;
|
||||
std::cout << "Cube = " << num << ", Triple = (" << a << "," << b << "," << c << ")" << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user