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. static int count(int N) {
  11. int count = 0;
  12. for (int i = N; i > 0; i /= 2) {
  13. for (int j = 0; j < i; j++) {
  14. count += 1;
  15. }
  16. }
  17. return count;
  18. }
  19.  
  20. public static void main (String[] args) throws java.lang.Exception
  21. {
  22. for (int i = 1; i < 16384; i *= 2) {
  23. System.out.format("%d %d%n", i, count(i));
  24. }
  25. }
  26. }
Success #stdin #stdout 0.08s 34244KB
stdin
Standard input is empty
stdout
1 1
2 3
4 7
8 15
16 31
32 63
64 127
128 255
256 511
512 1023
1024 2047
2048 4095
4096 8191
8192 16383