#include <bits/stdc++.h> #include <utility> #define nl '\n' using namespace std; using ll = long long; unordered_map<ll, ll> pair_count; int main() { cin.tie(0)->sync_with_stdio(0); ll n; cin>>n; for(ll a = 1; a <= n; a++){ for(ll b = 1; b <= a; b++){ pair_count[a*a+b*b]++; } } ll res = 0; for(int d=1; d<=n; d++){ for(int h=1; h<=d; h++){ //cerr<<d*d-h*h<<' '; //cerr<<pair_count[d*d-h*h]<<nl; res += pair_count[d*d-h*h]; } } cout<<res<<nl; 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> #include <utility> #define nl '\n' using namespace std; using ll = long long; unordered_map<ll, ll> pair_count; int main() { cin.tie(0)->sync_with_stdio(0); ll n; cin>>n; for(ll a = 1; a <= n; a++){ for(ll b = 1; b <= a; b++){ pair_count[a*a+b*b]++; } } ll res = 0; for(int d=1; d<=n; d++){ for(int h=1; h<=d; h++){ //cerr<<d*d-h*h<<' '; //cerr<<pair_count[d*d-h*h]<<nl; res += pair_count[d*d-h*h]; } } cout<<res<<nl; return 0; } |