#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
int n; cin >> n;
if (n < 3) {
cout << 0 << "\n";
return 0;
}
long long max_s = (long long)n * n - 1;
vector<int> boki(max_s + 1, 0);
for (int a = 1; ; ++a) {
long long a_sq = (long long)a * a;
if (a_sq > max_s) break;
for (int b = a; ; ++b) {
int b_sq = (long long)b * b;
int sum_sq = a_sq + b_sq;
if (sum_sq > max_s) break;
boki[sum_sq]++;
}
}
int res = 0;
for (int i = 1; i <= n; ++i) {
int d_sq = (int)i * i;
for (int j = 1; j < i; ++j) {
int h_sq = (int)j * j;
int s = d_sq - h_sq;
if (s > max_s) continue;
res += boki[s];
}
}
cout << res << "\n";
}
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 | #include <bits/stdc++.h> using namespace std; #define int long long int32_t main() { int n; cin >> n; if (n < 3) { cout << 0 << "\n"; return 0; } long long max_s = (long long)n * n - 1; vector<int> boki(max_s + 1, 0); for (int a = 1; ; ++a) { long long a_sq = (long long)a * a; if (a_sq > max_s) break; for (int b = a; ; ++b) { int b_sq = (long long)b * b; int sum_sq = a_sq + b_sq; if (sum_sq > max_s) break; boki[sum_sq]++; } } int res = 0; for (int i = 1; i <= n; ++i) { int d_sq = (int)i * i; for (int j = 1; j < i; ++j) { int h_sq = (int)j * j; int s = d_sq - h_sq; if (s > max_s) continue; res += boki[s]; } } cout << res << "\n"; } |
English