Official

D - |A + A| Editorial by evima


By experimenting with small cases, we can see that the answer is No only in the following cases:

  • \(K=2\) and \(M\) is not a multiple of \(2\).
  • \(K=4\) and \(M\) is not a multiple of \(4\).

Indeed, the answer is No for these cases even in larger instances.


[1] Case where \(K=2\) and \(M\) is not a multiple of \(2\)

All congruences are considered modulo \(M\).

First, since \(K=2\), the length of \(A\) must be \(2\) (where \(A_1\neq A_2\)).

The values that can be expressed as \(A_i+A_j\) are \(2A_1,2A_2,A_1+A_2\), which gives \(3\) possibilities. Among these, exactly \(2\) must have the same value modulo \(M\). Since \(A_1 \neq A_2\) and \(M\) is odd, we have \(2A_1 \not\equiv 2A_2 \pmod M\), so either \(A_1+A_2\) must be congruent to one of \(2A_1\) or \(2A_2\) modulo \(M\). However, if \(2A_1\equiv A_1+A_2\), then \(A_1\equiv A_2\), which contradicts \(A_1\neq A_2\). The same applies when \(2A_2\equiv A_1+A_2\).

[2] Case where \(K=4\) and \(M\) is not a multiple of \(4\)

If the length of \(A\) is at most \(2\), then there are at most \(3\) possible values for \(k\). On the other hand, if the length of \(A\) is at least \(5\), then there are at least \(5\) possible values for \(k\). Therefore, the only possible lengths for \(A\) are \(3\) and \(4\).

[2-1] Case where the length of \(A\) is \(3\)

Let \(A=(a,b,c)\) where \(a,b,c\) are mutually distinct.

In this case, exactly \(2\) pairs among \(2a,2b,2c,a+b,b+c,a+c\) must have the same value modulo \(M\).

Consider a graph where each value is a vertex, and we connect vertices with an edge if they have the same value modulo \(M\). By symmetry, we only need to consider the case where \(2a\) and \(b+c\), and \(2b\) and \(2c\) have the same values modulo \(M\), respectively.

If \(M\) is odd, then \(2b\equiv 2c\pmod M\) implies \(b\equiv c\pmod M\), but then \(2a\equiv b+c\equiv 2c\pmod M\), which is inappropriate.

If \(M\) is even, then either \(b\equiv c\pmod M\) or \(\displaystyle b\equiv c+\frac{M}{2} \pmod M\). The former is inappropriate as in the odd case, and the latter is also inappropriate since \(\displaystyle 2a-2b\equiv b+c-2b\equiv \frac{M}2\pmod M\).

[2-2] Case where the length of \(A\) is \(4\)

Let \(A=(a,b,c,d)\) where \(a,b,c,d\) are mutually distinct.

Let \(B_x=(a+x,b+x,c+x,d+x) \pmod M\) (i.e., each element is taken modulo \(M\)). Since the elements of \(B_x\) are mutually distinct, \(B_a,B_b,B_c,B_d\) are all identical as sets. Therefore, the common differences of \(A\), namely \(b-a,c-b,d-c,a-d\), must all be equal modulo \(M\), but since \(M\) is not a multiple of \(4\), it is impossible to construct such an \(A\).


The above is the proof for the No cases. All other cases are Yes, and can be constructed as follows:

  • Case \(K=M\): \(\displaystyle A=(0,1,\ldots,M-1)\)
  • Case \(K=2\): \(\displaystyle A=(0,M/2)\)
  • Case \(K=4\): \(\displaystyle A=(0,M/4,2M/4,3M/4)\)
  • Case where \(K\) is an even number \(\geq 6\): \(\displaystyle A=(0,2,3,\ldots,K/2)\)
  • Case where \(K\) is odd: \(\displaystyle A=(0,1,2,\ldots,(K-1)/2)\)

The first two are obvious. For the case where \(K\) is even, \(K\) distinct values \(0,2,3,\ldots,K\) appear, and for the case where \(K\) is odd, \(K\) distinct values \(0,1,2,\ldots,K-1\) appear.

Sample Implementation (Python3)

for _ in range(int(input())):

    def y(a):
        print("Yes")
        print(len(a))
        print(*a)

    m, k = map(int, input().split())
    if m == k:
        y([i for i in range(m)])
        continue
    if k == 2:
        if m % 2 == 0:
            y([0, m // 2])
            continue
        print("No")
        continue
    if k == 4:
        if m % 4 == 0:
            y([0, m // 4, m // 2, 3 * m // 4])
            continue
        print("No")
        continue
    if k % 2 == 1:
        y([i for i in range((k + 1) // 2)])
        continue
    a = [i + 1 for i in range(k // 2)]
    a[0] = 0
    y(a)

posted:
last update: