Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream>
- using namespace std;
- int solutie(int n)
- {
- int Z=0,U=0,S=0;
- while(n)
- {
- if(n%2==0)
- ++Z,S+=U; /// Unde: S+=U cati de 01 sunt
- if(n%2==1)
- S+=U*3,++U,S+=Z*2; /// Unde: S+=U*3 Cati de 11 sunt iar S+=Z Cati de 10 sunt
- n/=2;
- }
- return S;
- }
- int main()
- {
- int n,x;
- ifstream f("bibinar.in");
- f>>n;
- ofstream g("bibinar.out");
- while(n--)
- f>>x,g<<solutie(x)<<' ';
- f.close();
- g.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement