public class test {

    public static void main(String[] args) {

        boolean failed = false;
        for (int step = 0; !failed && step < Integer.MAX_VALUE; ++step) {

            for (int i = 1; i <= Integer.SIZE; i++) {
                int cand = 0;
                int num = 0;
                for (int j = 0; j < Integer.SIZE; j += i) {
                    cand |= 1 << j;
                    num++;
                }
                int tmp = Integer.bitCount(cand);
                if (tmp != num) {

                    failed = true;
                    System.out.println(
                            "1 Failed for :" + Integer.toHexString(cand)
                                    + ", expected:" + num +
                                    ", result: " + tmp);

                }
            }


            for (int i = 1; i <= Integer.SIZE; i++) {
                int cand = 0;
                int num = 0;
                for (int j = Integer.SIZE - 1; j >= 0; j -= i) {
                    cand |= 1 << j;
                    num++;
                }
                int tmp = Integer.bitCount(cand);
                if (tmp != num) {
                    failed = true;
                    System.out.println(
                            "2 Failed for :" + Integer.toHexString(cand)
                                    + ", expected:" + num +
                                    ", result: " + tmp);
                }
            }
        }
        System.out.println("result = " + failed);
    }

}
