fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. int q,i,c=0,n;
  13. int arr[]={1,2,4,8,16,32,64,128,256,512,1024,2048};
  14. q=Integer.parseInt(br.readLine());
  15. while(q-->0){
  16. n=Integer.parseInt(br.readLine());
  17. c=0;
  18. for(i=11;i>=0&&n>=0;i--){
  19. //System.out.println(arr[i]);
  20. if(n>=arr[i])
  21. {
  22. c++;
  23. n=n-arr[i];
  24. i++;
  25. //System.out.println("n "+n);
  26. }
  27. }
  28. System.out.println(c);
  29. }
  30. }
  31. }
Success #stdin #stdout 0.06s 380160KB
stdin
4
10
256
255
4096
stdout
2
1
8
2