#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e3 + 1;
unordered_map <ll, int> um;
void pre(){
ll x;
for(ll i = 1; i <= N; i++){
for(ll j = i; j <= N; j++){
x = i*i + j*j;
um[x] = 1;
}
}
return;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
pre();
ll n;
cin >> n;
ll x, zp, ans = 0;
for(ll k = 3; k <= n; k++){
x = k;
x *= x;
for(ll i = 1; i <= N; i++){
if(i*i > x) break;
zp = x - (i*i);
if(um.find(zp) != um.end()){
ans += um[zp];
}
}
}
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 31 32 33 34 35 36 37 38 39 40 41 42 | #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5e3 + 1; unordered_map <ll, int> um; void pre(){ ll x; for(ll i = 1; i <= N; i++){ for(ll j = i; j <= N; j++){ x = i*i + j*j; um[x] = 1; } } return; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); pre(); ll n; cin >> n; ll x, zp, ans = 0; for(ll k = 3; k <= n; k++){ x = k; x *= x; for(ll i = 1; i <= N; i++){ if(i*i > x) break; zp = x - (i*i); if(um.find(zp) != um.end()){ ans += um[zp]; } } } cout << ans << "\n"; return 0; } |
English