#include <bits/stdc++.h> #include <numeric> #include <tuple> using namespace std; tuple<int, int, int> kwadraty(int a) { for (int x = 1; x * x <= a * a; x++) { for (int y = x; x * x + y * y <= a * a; y++) { int z2 = a * a - x * x - y * y; int z = sqrt(z2); if (z > 0&&z * z == z2) { return make_tuple(x, y, z); } } } return make_tuple(-1, -1, -1); } int main() { int a; cin >> a; int x, y, z; int ile=0; for(int i=3;i<=a;i++) { tie(x, y, z) = kwadraty(i); if(x!=-1) { if(x==z&&y==z&&x==y) ile++; if((x==z||y==z||x==y)&&(x!=z||y!=z||x!=y)) ile+=2; if(x!=z&&y!=z&&x!=y) ile+=3; } } cout<<ile; 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 53 | #include <bits/stdc++.h> #include <numeric> #include <tuple> using namespace std; tuple<int, int, int> kwadraty(int a) { for (int x = 1; x * x <= a * a; x++) { for (int y = x; x * x + y * y <= a * a; y++) { int z2 = a * a - x * x - y * y; int z = sqrt(z2); if (z > 0&&z * z == z2) { return make_tuple(x, y, z); } } } return make_tuple(-1, -1, -1); } int main() { int a; cin >> a; int x, y, z; int ile=0; for(int i=3;i<=a;i++) { tie(x, y, z) = kwadraty(i); if(x!=-1) { if(x==z&&y==z&&x==y) ile++; if((x==z||y==z||x==y)&&(x!=z||y!=z||x!=y)) ile+=2; if(x!=z&&y!=z&&x!=y) ile+=3; } } cout<<ile; return 0; } |