#include <bits/stdc++.h>
using namespace std;
int countAquariums(int n){
unordered_set<int> sums_of_two_squares;
unordered_set<int> differences_of_two_squares;
for(int a=1; a<=n; ++a){
for(int b=1; b<=n; ++b){
sums_of_two_squares.insert(a*a + b*b);
}
}
for(int k=1; k<=n; ++k){
for(int h=1; h<=n; ++h){
differences_of_two_squares.insert(k * k - h * h);
}
}
int count=0;
for(int sum:sums_of_two_squares){
if(differences_of_two_squares.find(sum)!=differences_of_two_squares.end()){
count++;
}
}
return count;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin>>n;
cout<<countAquariums(n)<<endl;
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 | #include <bits/stdc++.h> using namespace std; int countAquariums(int n){ unordered_set<int> sums_of_two_squares; unordered_set<int> differences_of_two_squares; for(int a=1; a<=n; ++a){ for(int b=1; b<=n; ++b){ sums_of_two_squares.insert(a*a + b*b); } } for(int k=1; k<=n; ++k){ for(int h=1; h<=n; ++h){ differences_of_two_squares.insert(k * k - h * h); } } int count=0; for(int sum:sums_of_two_squares){ if(differences_of_two_squares.find(sum)!=differences_of_two_squares.end()){ count++; } } return count; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); int n; cin>>n; cout<<countAquariums(n)<<endl; return 0; } |
English