#include <bits/stdc++.h>
using namespace std;
#define int int64_t
#define MAX 25000000
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
vector<int> sum_cnt(MAX + 1, 0);
for (int a = 1; a <= 5000; a++) {
for (int b = a; b <= 5000; b++) {
int s = a * a + b * b;
if (s > MAX) {
break;
}
sum_cnt[s]++;
}
}
int n;
cin >> n;
int cnt = 0;
for (int d = 1; d <= n; d++) {
for (int h = 1; h < d; h++) {
int S = d * d - h * h;
if (S < 2) {
continue;
}
if (S > MAX) {
continue;
}
cnt += sum_cnt[S];
}
}
cout << cnt;
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 | #include <bits/stdc++.h> using namespace std; #define int int64_t #define MAX 25000000 int32_t main() { ios::sync_with_stdio(0); cin.tie(0); vector<int> sum_cnt(MAX + 1, 0); for (int a = 1; a <= 5000; a++) { for (int b = a; b <= 5000; b++) { int s = a * a + b * b; if (s > MAX) { break; } sum_cnt[s]++; } } int n; cin >> n; int cnt = 0; for (int d = 1; d <= n; d++) { for (int h = 1; h < d; h++) { int S = d * d - h * h; if (S < 2) { continue; } if (S > MAX) { continue; } cnt += sum_cnt[S]; } } cout << cnt; return 0; } |
English