Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. int main()
  2. {
  3. int a=0,b=0,n=0,c=0,d=0,p=0;
  4. cout << "wpisz liczbe naturalna: ";
  5. cin>>n;
  6. if (n<0) {
  7. cout << "n musi byc wieksze od 0";
  8. }
  9. else {
  10. while (p!=n) {
  11. do {
  12. a=a+1;
  13. p=a*a+b*b+c*c+d*d;
  14. //cout <<"1 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
  15. if (p>n){
  16. a=a-1;
  17. do {
  18. b=b+1;
  19. p=a*a+b*b+c*c+d*d;
  20. //cout <<"2 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
  21. if (b>sqrt(n-(p-(b*b)))){
  22. b=b-1;
  23. do {
  24. c=c+1;
  25. p=a*a+b*b+c*c+d*d;
  26. //cout <<"3 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
  27. if (c>sqrt(n-(p-(c*c)))){
  28. c=c-1;
  29. do {
  30. d=d+1;
  31. p=a*a+b*b+c*c+d*d;
  32. //cout <<"4 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
  33.  
  34. } while (p<n);
  35. }
  36. } while (p<n);
  37. }
  38. } while (p<n);
  39. }
  40.  
  41. } while (p<n);
  42. if (p>n) {
  43. int i=0;
  44. i=i+1;
  45. a=a-i;
  46. b=0;
  47. c=0;
  48. d=0;
  49. do {
  50. b=b+1;
  51. p=a*a+b*b+c*c+d*d;
  52. //cout <<"2 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
  53. if (b>sqrt(n-(p-(b*b)))){
  54. b=b-1;
  55. do {
  56. c=c+1;
  57. p=a*a+b*b+c*c+d*d;
  58. //cout <<"3 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
  59. if (c>sqrt(n-(p-(c*c)))){
  60. c=c-1;
  61. do {
  62. d=d+1;
  63. p=a*a+b*b+c*c+d*d;
  64. //cout <<"4 "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p<<endl;
  65.  
  66. } while (p<n);
  67. }
  68. } while (p<n);
  69. }
  70. } while (p<n);
  71. }
  72. }
  73. }
  74. cout <<"mozna ja przedstawic za pomoca kwadratow 4 liczb naturalnych: "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<p;
  75.  
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement