#include<bits/stdc++.h>
using namespace std;
typedef pair < int, int > pii;
const int t = 25'000'003;
vector < pii > v[t];
int main(){
std::ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int kwadrat = n * n;
for(int i = 1; i <= n; i++){
for(int j = i; j <= n; j++){
int x = i * i + j * j;
if(x <= kwadrat) v[x].push_back({i, j});
}
}
int wyn = 0;
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j ++){
int x = j * j - i * i;
for(pii k: v[x]){
if(max(k.first, k.second) <= i){
if(k.first == k.second && k.second == i) wyn++;
else if(k.first == k.second || k.first == i || k.second == i) wyn += 2;
else wyn += 3;
}
}
}
}
cout << wyn << "\n";
}
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 | #include<bits/stdc++.h> using namespace std; typedef pair < int, int > pii; const int t = 25'000'003; vector < pii > v[t]; int main(){ std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; int kwadrat = n * n; for(int i = 1; i <= n; i++){ for(int j = i; j <= n; j++){ int x = i * i + j * j; if(x <= kwadrat) v[x].push_back({i, j}); } } int wyn = 0; for(int i = 1; i <= n; i++){ for(int j = i + 1; j <= n; j ++){ int x = j * j - i * i; for(pii k: v[x]){ if(max(k.first, k.second) <= i){ if(k.first == k.second && k.second == i) wyn++; else if(k.first == k.second || k.first == i || k.second == i) wyn += 2; else wyn += 3; } } } } cout << wyn << "\n"; } |
English