#include <iostream> #include <vector> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::vector<int> possibleSquares; int n; std::cin >> n; for(int i=1; i<=n;i++){ possibleSquares.push_back(i*i); //std::cout<<i*i<<" "; } //std::cout<<"\n"; int res = 0; for(int i = 2; i <possibleSquares.size();i++){ //std::cout<<"n:" <<possibleSquares[i]<<"\n"; for(int j = i-1;j>=0;j--){ if(possibleSquares[j]*3< possibleSquares[i]){ break; } for(int k = j;k>=0;k--){ if(possibleSquares[j] + possibleSquares[k]*2 < possibleSquares[i]){ break; } if(possibleSquares[j] + possibleSquares[k] >= possibleSquares[i]){ continue; } for(int l = k;l>=0;l--){ if(possibleSquares[j] + possibleSquares[k]+possibleSquares[l] < possibleSquares[i]){ break; } //std::cout << possibleSquares[j] << " "<<possibleSquares[k] << " "<<possibleSquares[l]<<"\n"; if(possibleSquares[j] + possibleSquares[k]+possibleSquares[l]==possibleSquares[i]){ if( j==k || k==l || l==j){ res += 2; } else{ res+=3; } } } } } } std::cout<<res; 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 43 44 45 46 47 48 49 50 51 52 | #include <iostream> #include <vector> int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::vector<int> possibleSquares; int n; std::cin >> n; for(int i=1; i<=n;i++){ possibleSquares.push_back(i*i); //std::cout<<i*i<<" "; } //std::cout<<"\n"; int res = 0; for(int i = 2; i <possibleSquares.size();i++){ //std::cout<<"n:" <<possibleSquares[i]<<"\n"; for(int j = i-1;j>=0;j--){ if(possibleSquares[j]*3< possibleSquares[i]){ break; } for(int k = j;k>=0;k--){ if(possibleSquares[j] + possibleSquares[k]*2 < possibleSquares[i]){ break; } if(possibleSquares[j] + possibleSquares[k] >= possibleSquares[i]){ continue; } for(int l = k;l>=0;l--){ if(possibleSquares[j] + possibleSquares[k]+possibleSquares[l] < possibleSquares[i]){ break; } //std::cout << possibleSquares[j] << " "<<possibleSquares[k] << " "<<possibleSquares[l]<<"\n"; if(possibleSquares[j] + possibleSquares[k]+possibleSquares[l]==possibleSquares[i]){ if( j==k || k==l || l==j){ res += 2; } else{ res+=3; } } } } } } std::cout<<res; return 0; } |