#include <bits/stdc++.h> #define fi first #define se second typedef long long ll; using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); ll ans = 0; int n; cin >> n; unordered_map<int, int> m; for (int a = 1; a <= n; ++a) for (int b = a; b <= n; ++b) ++m[a * a + b * b]; for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) ans += m[j * j - i * i]; cout << ans << '\n'; 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 | #include <bits/stdc++.h> #define fi first #define se second typedef long long ll; using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false); ll ans = 0; int n; cin >> n; unordered_map<int, int> m; for (int a = 1; a <= n; ++a) for (int b = a; b <= n; ++b) ++m[a * a + b * b]; for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) ans += m[j * j - i * i]; cout << ans << '\n'; return 0; } |