#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int n;
cin >> n;
int mx_pr = n * n - 1;
vector<int> nums(mx_pr + 1, 0);
for (int i = 1; ; i++) {
int a_sq = i * i;
if (a_sq > mx_pr) break;
for (int j = i; ; j++) {
int s = a_sq + j * j;
if (s > mx_pr) break;
nums[s]++;
}
}
int wyn = 0;
for (int i = 1; i <= n; i++) {
int prz = i * i;
for (int j = 1; j < i; j++) {
int s = prz - j * j;
if (s < 2) continue;
if (s > mx_pr) continue;
wyn += nums[s];
}
}
cout << wyn;
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 | #include <bits/stdc++.h> using namespace std; int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::cout.tie(nullptr); int n; cin >> n; int mx_pr = n * n - 1; vector<int> nums(mx_pr + 1, 0); for (int i = 1; ; i++) { int a_sq = i * i; if (a_sq > mx_pr) break; for (int j = i; ; j++) { int s = a_sq + j * j; if (s > mx_pr) break; nums[s]++; } } int wyn = 0; for (int i = 1; i <= n; i++) { int prz = i * i; for (int j = 1; j < i; j++) { int s = prz - j * j; if (s < 2) continue; if (s > mx_pr) continue; wyn += nums[s]; } } cout << wyn; return 0; } |
English