#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int* arr = new int[50000001];
std::fill(arr, arr + 50000001, 0);
for (int a = 1; a <= 5000; a++) {
for (int b = a; b <= 5000; b++) {
int s = a * a + b * b;
arr[s]++;
}
}
int result = 0;
for (int h = 1; h <= n; h++) {
for (int k = 1; k <= n; k++) {
int s = k*k - h*h;
if (s > 0 && arr[s] > 0) {
//cout << i << " " << h << " " << arr[s] << endl;
result += arr[s];
}
}
}
cout << result;
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> #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; int* arr = new int[50000001]; std::fill(arr, arr + 50000001, 0); for (int a = 1; a <= 5000; a++) { for (int b = a; b <= 5000; b++) { int s = a * a + b * b; arr[s]++; } } int result = 0; for (int h = 1; h <= n; h++) { for (int k = 1; k <= n; k++) { int s = k*k - h*h; if (s > 0 && arr[s] > 0) { //cout << i << " " << h << " " << arr[s] << endl; result += arr[s]; } } } cout << result; return 0; } |
English