fork download
  1.  
  2. class Ideone {
  3. public static void main (String[] args) {
  4. for (int input = 100; input <= 1000; input += 100) {
  5.  
  6. int output = calc(input);
  7.  
  8. double ratio = (double) output / input;
  9. System.out.printf("%4d -> %4d : ratio of %f%n", input, output, ratio);
  10. }
  11. }
  12.  
  13. public static int calc(int N) {
  14. int count = 0;
  15. for (int i = N; i > 0; i /= 2) {
  16. for (int j = 0; j < i; j++) {
  17. count += 1;
  18. }
  19. }
  20. return count;
  21. }
  22. }
Success #stdin #stdout 0.06s 4386816KB
stdin
Standard input is empty
stdout
 100 ->  197 : ratio of 1.970000
 200 ->  397 : ratio of 1.985000
 300 ->  596 : ratio of 1.986667
 400 ->  797 : ratio of 1.992500
 500 ->  994 : ratio of 1.988000
 600 -> 1196 : ratio of 1.993333
 700 -> 1394 : ratio of 1.991429
 800 -> 1597 : ratio of 1.996250
 900 -> 1796 : ratio of 1.995556
1000 -> 1994 : ratio of 1.994000