#include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<set> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ll n; cin>>n; vector<ll>ca(n*n+10,0),cb(n*n+10,0); for(ll a = 1;a<n;++a){ for (ll b = a;b<n;++b){ if(a*a+b*b>=n*n){ break; } ca[a*a+b*b]++; } } for(ll a = 1;a<n;++a){ for (ll b = a+1;b<=n;++b){ cb[b*b-a*a]++; } } ll ans = 0; for(int i = 0;i<cb.size();i++){ ans+=ca[i]*cb[i]; } cout<<ans; 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 | #include<iostream> #include<vector> #include<algorithm> #include<cmath> #include<set> #define ll long long using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); ll n; cin>>n; vector<ll>ca(n*n+10,0),cb(n*n+10,0); for(ll a = 1;a<n;++a){ for (ll b = a;b<n;++b){ if(a*a+b*b>=n*n){ break; } ca[a*a+b*b]++; } } for(ll a = 1;a<n;++a){ for (ll b = a+1;b<=n;++b){ cb[b*b-a*a]++; } } ll ans = 0; for(int i = 0;i<cb.size();i++){ ans+=ca[i]*cb[i]; } cout<<ans; return 0; } |