#include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; ios::sync_with_stdio(0); cin.tie(0); int maxi = 24999999; vector<int> tab(maxi + 1, 0); for (int y = 1; y <= 5000; y++) { for (int i = y; i <= 5000; i++) { int s = y * y + i * i; if (s > maxi) break; tab[s]++; } } int result = 0; for (int k = 1; k <= n; k++) { for (int h = 1; h < k; h++) { int s = k * k - h * h; if (s < 2 or s > maxi) continue; result += tab[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 | #include <iostream> #include <vector> using namespace std; int main() { int n; cin >> n; ios::sync_with_stdio(0); cin.tie(0); int maxi = 24999999; vector<int> tab(maxi + 1, 0); for (int y = 1; y <= 5000; y++) { for (int i = y; i <= 5000; i++) { int s = y * y + i * i; if (s > maxi) break; tab[s]++; } } int result = 0; for (int k = 1; k <= n; k++) { for (int h = 1; h < k; h++) { int s = k * k - h * h; if (s < 2 or s > maxi) continue; result += tab[s]; } } cout << result; return 0; } |