#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
int result = 0;
set<int> squares;
cin >> n;
for (int i = 1; i <= n; i++) {
squares.insert(i * i);
}
for (int a = 1; a <= n; a++) {
for (int b = a; b <= n; b++) {
for (int h = 1; h <= n; h++) {
if (a * a + b * b + h * h > n * n) break;
if (squares.find(a * a + b * b + h * h) != squares.end())
result++;
}
}
}
cout << result << "\n";
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 | #include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; int result = 0; set<int> squares; cin >> n; for (int i = 1; i <= n; i++) { squares.insert(i * i); } for (int a = 1; a <= n; a++) { for (int b = a; b <= n; b++) { for (int h = 1; h <= n; h++) { if (a * a + b * b + h * h > n * n) break; if (squares.find(a * a + b * b + h * h) != squares.end()) result++; } } } cout << result << "\n"; return 0; } |
English