#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int>ab;
int main(){
int n, res = 0; cin >> n;
for(auto a = 1; a <= 5000; ++a){
for(auto b = 1; b <= a; ++b){
ab[a*a+b*b]++;
}
}
for(auto x = 1; x <= n; ++x){
for(auto h = 1; h < x; ++h){
res += ab[x*x-h*h];
}
}
cout << res;
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | #include <bits/stdc++.h> using namespace std; unordered_map<int, int>ab; int main(){ int n, res = 0; cin >> n; for(auto a = 1; a <= 5000; ++a){ for(auto b = 1; b <= a; ++b){ ab[a*a+b*b]++; } } for(auto x = 1; x <= n; ++x){ for(auto h = 1; h < x; ++h){ res += ab[x*x-h*h]; } } cout << res; } |
English