#include <iostream>
#include <cmath>
#include <vector>
int main() {
int n;
std::cin >> n;
int count = 0;
// Precompute squares up to n to avoid repeated calculations
std::vector<int> squares(n + 1);
for (int i = 1; i <= n; i++) {
squares[i] = i * i;
}
// For each possible diagonal length d
for (int d = 1; d <= n; d++) {
long long d_squared = static_cast<long long>(d) * d;
// For each possible a (first dimension of base)
for (int a = 1; a * a <= d_squared; a++) {
long long a_squared = static_cast<long long>(a) * a;
// For each possible b (second dimension of base), where a ≤ b
for (int b = a; b * b <= d_squared - a_squared; b++) {
long long b_squared = static_cast<long long>(b) * b;
// Calculate h²
long long h_squared = d_squared - a_squared - b_squared;
// Skip if h² is not positive
if (h_squared <= 0) continue;
// Check if h² is a perfect square (h is an integer)
int h = static_cast<int>(std::sqrt(h_squared));
if (static_cast<long long>(h) * h == h_squared) {
count++;
}
}
}
}
std::cout << count << std::endl;
return 0;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | #include <iostream> #include <cmath> #include <vector> int main() { int n; std::cin >> n; int count = 0; // Precompute squares up to n to avoid repeated calculations std::vector<int> squares(n + 1); for (int i = 1; i <= n; i++) { squares[i] = i * i; } // For each possible diagonal length d for (int d = 1; d <= n; d++) { long long d_squared = static_cast<long long>(d) * d; // For each possible a (first dimension of base) for (int a = 1; a * a <= d_squared; a++) { long long a_squared = static_cast<long long>(a) * a; // For each possible b (second dimension of base), where a ≤ b for (int b = a; b * b <= d_squared - a_squared; b++) { long long b_squared = static_cast<long long>(b) * b; // Calculate h² long long h_squared = d_squared - a_squared - b_squared; // Skip if h² is not positive if (h_squared <= 0) continue; // Check if h² is a perfect square (h is an integer) int h = static_cast<int>(std::sqrt(h_squared)); if (static_cast<long long>(h) * h == h_squared) { count++; } } } } std::cout << count << std::endl; return 0; } |
English