fork download
  1. #include<iostream>
  2. using namespace std;
  3. long long int pow2[35]={1,2};
  4. short T,p;
  5. long int H,s;
  6. int main()
  7. {
  8. for(int x=1;x<35;x++)
  9. pow2[x]=pow2[x-1]*2;
  10. cin>>T;
  11. while(T--)
  12. {
  13. cin>>H;
  14. p=s=0;
  15. while(H!=0)
  16. {
  17. H-=pow2[p];
  18. s++;
  19. if(H%pow2[p+1]!=0)
  20. {
  21. H-=pow2[p];
  22. s++;
  23. }
  24. p++;
  25. }
  26. cout<<s<<endl;
  27. }
  28. return 0;
  29. }
Success #stdin #stdout 0s 3300KB
stdin
4
1
3
5
987651432
stdout
1
2
3
47