#include <bits/stdc++.h> using namespace std; int il[50000002]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int a=1; a<=n; a++) for(int b=a; b<=n; b++) il[a*a+b*b]++; long long ret=0; for(int s=2; s<=n; s++) for(int h=1; h<s; h++) ret += il[s*s-h*h]; cout << ret << '\n'; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <bits/stdc++.h> using namespace std; int il[50000002]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int a=1; a<=n; a++) for(int b=a; b<=n; b++) il[a*a+b*b]++; long long ret=0; for(int s=2; s<=n; s++) for(int h=1; h<s; h++) ret += il[s*s-h*h]; cout << ret << '\n'; } |