code: protected static long luby(final long i) {
          long res = 0;
          long k;
          for (k = 1; res == 0 && k < 64; k++) {
              if (i == (1L << k) - 1) { res = 1L << (k - 1); }
          }
          k = 1;
          while (res == 0) {
              if ((1L << (k - 1)) <= i && i < (1L << k) - 1) { res = luby(i - (1L << (k - 1)) + 1); }
              k++;
          }
          return res;
      }
docs: Returns the next number in the luby sequence.
  @param i the base value
  @return the next number in the luby sequence