Solution of Recycled problem

Approach #1 (Costin Andrei Oncescu)

Let y = 2i be the smallest power of 2 strictly greater than K. We choose as the elements of S all values in the interval [y-k, y-1].

Consequences:

  • We already have exactly K values in S. Each value will constitute a subset by itself, and provide a distinct value in F(S).
  • For any two values a, b ∈ [y-k, y-1], we have (a OR b) ∈ [y-k, y-1]. In other words, there will be no additional values generated by larger subsets of S. To better understand the intuition behind this, try to imagine the binary representation of all values in the given interval.

Approach #2 (Sergiu Puscas)

Since the constraints for this problem are not very strict, we can try to construct a solution in the following way:

  • Start with S = {1} (or any other value).
  • While |F(S)| ≠ K:
    • If |F(S)| < K, choose a new value randomly and add it to the set.
    • If |F(S)| > K, choose an existing value randomly and remove it from the set.
  • Print the elements of S.

This approach finds a solution relatively quickly, assuming an efficient implementation of the method that computes F(S).

In practice, it yields a set that is much smaller than than K elements.

Questions?

Sponsors Gold