Advertisement
a53

Cerc5

a53
Nov 9th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. using namespace std;
  5.  
  6. int n , x[35 + 1] , uz[35 + 1], gata;
  7.  
  8. void Afisare()
  9. {
  10. gata = true;
  11. for(int i = 1 ; i <= n ; i ++)
  12. cout << x[i] << " ";
  13. cout << "\n";
  14. }
  15.  
  16. bool OK(int k)
  17. {
  18. if(k == 1)
  19. return true;
  20. if(sqrt(x[k] + x[k-1]) != (int)sqrt(x[k] + x[k-1]))
  21. return false;
  22. if(k == n)
  23. if(sqrt(x[k] + x[1]) != (int)sqrt(x[k] + x[1]))
  24. return false;
  25. return true;
  26. }
  27.  
  28. void Back(int k)
  29. {
  30. for(int i = 1 ; i <= n && ! gata; i ++)
  31. if(uz[i] == 0)
  32. {
  33. uz[i] = 1;
  34. x[k] = i;
  35. if(OK(k))
  36. {
  37. if(k == n)
  38. Afisare();
  39. else
  40. Back(k +1);
  41. }
  42. uz[i] = 0;
  43. }
  44. }
  45.  
  46. int main()
  47. {
  48. cin >> n;
  49.  
  50. x[1] = 1, uz[1] = 1;
  51. Back(2);
  52.  
  53. if(! gata)
  54. cout << "nu exista";
  55.  
  56. return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement