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 final int longestZeroSequence(int value) {
  11. int longest = 0;
  12. int shift = Integer.numberOfTrailingZeros(value) + 1;
  13. value >>>= shift;
  14. while (value != 0) {
  15. shift = Integer.numberOfTrailingZeros(value) + 1;
  16. if (shift > longest) {
  17. longest = shift - 1;
  18. }
  19. value >>>= shift;
  20. }
  21. return longest;
  22. }
  23.  
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. for (int i = 0; i < 2000000; i += 100000) {
  27. System.out.printf("%d is %s with longest %d\n", i, Integer.toString(i, 2), longestZeroSequence(i));
  28. }
  29. }
  30. }
Success #stdin #stdout 0.06s 4386816KB
stdin
Standard input is empty
stdout
0 is 0 with longest 0
100000 is 11000011010100000 with longest 4
200000 is 110000110101000000 with longest 4
300000 is 1001001001111100000 with longest 2
400000 is 1100001101010000000 with longest 4
500000 is 1111010000100100000 with longest 4
600000 is 10010010011111000000 with longest 2
700000 is 10101010111001100000 with longest 2
800000 is 11000011010100000000 with longest 4
900000 is 11011011101110100000 with longest 1
1000000 is 11110100001001000000 with longest 4
1100000 is 100001100100011100000 with longest 4
1200000 is 100100100111110000000 with longest 2
1300000 is 100111101011000100000 with longest 3
1400000 is 101010101110011000000 with longest 2
1500000 is 101101110001101100000 with longest 3
1600000 is 110000110101000000000 with longest 4
1700000 is 110011111000010100000 with longest 4
1800000 is 110110111011101000000 with longest 1
1900000 is 111001111110111100000 with longest 2