Change the loop (you increase the complexity to O (N ^ 2) because you call the power () in each iteration of the loop):
for (int e = bitSet.cardinality(), i = 0; i < e; ++i ) { indexes.add(nextSetBit); nextSetBit = bitSet.nextSetBit(nextSetBit + 1); }
source share