Advertisement
heian

Untitled

Jun 10th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int n;
  6.  
  7. int opus(int i)
  8. {
  9. if(i==1) return 2;
  10. return 1;
  11. }
  12.  
  13. int Solutie(int poz)
  14. {
  15. if(poz==1) return 1;
  16. if(poz==2) return 2;
  17. if(poz==3) return 2;
  18. if(poz==4) return 1;
  19.  
  20. int p=4, k=1;
  21. while(p<n)
  22. {
  23. p*=4;
  24. k++;
  25. }
  26. int sfert = p/4;
  27. int cadran;
  28. if(poz>=1 && poz<=sfert) cadran=1;
  29. if(poz>sfert && poz<=2*sfert) cadran=2;
  30. if(poz>sfert*2 && poz<=3*sfert) cadran=3;
  31. if(poz>sfert*3 && poz<=sfert*4) cadran=4;
  32.  
  33. //if(cadran==1) cadranul niciodata nu va fi 1
  34. //return Solutie(poz);
  35. if(cadran==2)
  36. return opus(Solutie(poz - sfert*1));
  37. if(cadran==3)
  38. return opus(Solutie(poz - sfert*2));
  39. //if(cadran==4)
  40. return Solutie(poz - sfert*3);
  41. }
  42.  
  43. int main()
  44. {
  45. cin>>n;
  46. cout<<Solutie(n)<<"\n";
  47. return 0;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement