#P1978. Maximum k-Set

    ID: 15260 Type: Default 1000ms 256MiB

Maximum k-Set

Maximum k-Set

A set in mathematics is a collection of distinct objects. In this problem, we consider a special kind of set called the k-set. A k-set is defined as follows:

  • Unordered: The elements in a set do not follow any specific order.
  • Distinct: Every element in the set is unique.
  • Deterministic: For any element x, either x belongs to the set or it does not.
  • k-condition: For every element \( x \) in the set, \( kx \) should not be in the set. In other words, \( \forall x \text{ in the set, } kx \notin \text{set} \).

You are given a set \( S \) of n distinct integers and an integer \( k \). Your task is to choose a maximum (largest in terms of the number of elements) subset \( T \) of \( S \) which is a k-set, that is, for every \( x \in T \), \( kx \notin T \) holds.

Note: If there are multiple answers, any one of them is acceptable.

inputFormat

The first line contains two integers n and k (n is the number of elements in the set and k is a given integer).

The second line contains n distinct integers representing the set \( S \).

outputFormat

Output two lines. The first line contains an integer representing the size of the maximum k-set found.

The second line contains the elements of the k-set in increasing order separated by a single space.

sample

3 2
1 2 3
2

1 3

</p>