Advertisement
a53

bibinar

a53
Jan 19th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3.  
  4. int solutie(int n)
  5. {
  6. int Z=0,U=0,S=0;
  7. while(n)
  8. {
  9. if(n%2==0)
  10. ++Z,S+=U; /// Unde: S+=U cati de 01 sunt
  11. if(n%2==1)
  12. S+=U*3,++U,S+=Z*2; /// Unde: S+=U*3 Cati de 11 sunt iar S+=Z Cati de 10 sunt
  13. n/=2;
  14. }
  15. return S;
  16. }
  17.  
  18. int main()
  19. {
  20. int n,x;
  21. ifstream f("bibinar.in");
  22. f>>n;
  23. ofstream g("bibinar.out");
  24. while(n--)
  25. f>>x,g<<solutie(x)<<' ';
  26. f.close();
  27. g.close();
  28. return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement