Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int main()
- {
- int a=0,b=0,n=0,c=0,d=0,p=0;
- cout << "wpisz liczbe naturalna: ";
- cin>>n;
- if (n<0) {
- cout << "n musi byc wieksze od 0";
- }
- else {
- while (p!=n) {
- do {
- a=a+1;
- p=a*a+b*b+c*c+d*d;
- //cout <<"1 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
- if (p>n){
- a=a-1;
- do {
- b=b+1;
- p=a*a+b*b+c*c+d*d;
- //cout <<"2 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
- if (b>sqrt(n-(p-(b*b)))){
- b=b-1;
- do {
- c=c+1;
- p=a*a+b*b+c*c+d*d;
- //cout <<"3 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
- if (c>sqrt(n-(p-(c*c)))){
- c=c-1;
- do {
- d=d+1;
- p=a*a+b*b+c*c+d*d;
- //cout <<"4 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
- } while (p<n);
- }
- } while (p<n);
- }
- } while (p<n);
- }
- } while (p<n);
- if (p>n) {
- int i=0;
- i=i+1;
- a=a-i;
- b=0;
- c=0;
- d=0;
- do {
- b=b+1;
- p=a*a+b*b+c*c+d*d;
- //cout <<"2 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
- if (b>sqrt(n-(p-(b*b)))){
- b=b-1;
- do {
- c=c+1;
- p=a*a+b*b+c*c+d*d;
- //cout <<"3 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
- if (c>sqrt(n-(p-(c*c)))){
- c=c-1;
- do {
- d=d+1;
- p=a*a+b*b+c*c+d*d;
- //cout <<"4 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
- } while (p<n);
- }
- } while (p<n);
- }
- } while (p<n);
- }
- }
- }
- cout <<"mozna ja przedstawic za pomoca kwadratow 4 liczb naturalnych: "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement