Блог пользователя m.khooryani

Автор m.khooryani, история, 8 лет назад, По-английски
        int limit = 1 << n;
        for (int i = 0; i < limit; i++) {
            if (Integer.bitCount(i) >= 3) {
                System.out.println(i);
            }
        }
  • Проголосовать: нравится
  • +3
  • Проголосовать: не нравится

»
8 лет назад, # |
  Проголосовать: нравится +27 Проголосовать: не нравится

There's technically no asymptotically better way. Note that the number of integers in that range that have bitCount < 3 is So the total number of integers you would be printing out is O(2n) - O(n2) = O(2n),  which is at least necessary asymptotically.