#include<bits/stdc++.h> typedef long long ll; using namespace std; double pierwiastek(ll liczba) { double x=liczba/2; while(fabs(x-liczba/x)>0.0001) { x=(x+liczba/x)/2; if(x*x==liczba) break; } if(round(x)*round(x)==liczba) return round(x); return x; } int main(){ ll n; cin>>n; string t=""; ll wynik=0; for(ll i=1;i<n;i++){ for(ll j=1;j<n;j++){ for(ll h=1;h<n;h++){ string pom=""; pom+=to_string(i); pom+=" "; pom+=to_string(j); pom+=" "; pom+=to_string(h); if(pierwiastek((i*i)+(j*j)+(h*h))==int(pierwiastek((i*i)+(j*j)+(h*h))) && pierwiastek((i*i)+(j*j)+(h*h))<=n && t.find(pom)==string::npos){ wynik++; t+=to_string(i); t+=" "; t+=to_string(j); t+=" "; t+=to_string(h); t+=";"; t+=to_string(j); t+=" "; t+=to_string(i); t+=" "; t+=to_string(h); t+=";"; } } } } cout<<wynik; }
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 54 55 56 57 58 | #include<bits/stdc++.h> typedef long long ll; using namespace std; double pierwiastek(ll liczba) { double x=liczba/2; while(fabs(x-liczba/x)>0.0001) { x=(x+liczba/x)/2; if(x*x==liczba) break; } if(round(x)*round(x)==liczba) return round(x); return x; } int main(){ ll n; cin>>n; string t=""; ll wynik=0; for(ll i=1;i<n;i++){ for(ll j=1;j<n;j++){ for(ll h=1;h<n;h++){ string pom=""; pom+=to_string(i); pom+=" "; pom+=to_string(j); pom+=" "; pom+=to_string(h); if(pierwiastek((i*i)+(j*j)+(h*h))==int(pierwiastek((i*i)+(j*j)+(h*h))) && pierwiastek((i*i)+(j*j)+(h*h))<=n && t.find(pom)==string::npos){ wynik++; t+=to_string(i); t+=" "; t+=to_string(j); t+=" "; t+=to_string(h); t+=";"; t+=to_string(j); t+=" "; t+=to_string(i); t+=" "; t+=to_string(h); t+=";"; } } } } cout<<wynik; } |