#P11010. Equal‐Sum Partition Game

    ID: 13061 Type: Default 1000ms 256MiB

Equal‐Sum Partition Game

Equal‐Sum Partition Game

Alice and Bob are playing a game with two positive integers (n) and (k) (with (2 \le k \le n)). In the game, the players proceed as follows:

  1. First, Alice chooses a sequence (a = [a_1,a_2,\dots,a_k]) of positive integers satisfying [ \sum_{i=1}^{k} a_i = n. ]
  2. Then Bob must choose an integer (m \ge 2) such that it is possible to partition the multiset of numbers in (a) into (m) nonempty (multiset) groups whose sums are all equal. (Note that the partition is by groups – the order does not matter.)

    Bob wins if he is able to find such an (m); otherwise, Alice wins. Both players play optimally. Your task is to answer (T) queries. For each query, given (n) and (k), determine who wins under optimal play.


    Important observations and optimal strategies:
  • Any valid partition into \(m\) groups requires that \(m\) divides \(n\) (since each group must sum to \(\frac{n}{m}\)). Also, since there are only \(k\) numbers, we must have \(m \le k\) (except the trivial case when \(k=n\), which forces \(a_i=1\) for all \(i\)).
  • When \(n\) is prime, the only divisor other than 1 is \(n\) itself. Hence if \(k<n\) then Bob has no choice (since \(m=n\) is not allowed when \(k<n\)) and Alice wins. When \(k=n\), the only sequence is \([1,1,\dots,1]\) and Bob can choose \(m=n\) to win.
  • When \(n\) is composite, Bob’s winning move is typically to choose \(m=2\) (or another proper divisor) provided that the sequence chosen by Alice is forced to have a structure that admits an equal‐sum partition. In fact, it can be shown that when \(n\) is composite the outcome is completely determined by the freedom Alice has in choosing the sequence. In particular, it turns out that if \n - k\ (i.e. the extra amount above the minimal sum of \(k\) ones) is very small then Alice has little freedom. One may prove that in this case Bob wins if

    \[ k \ge n - \Bigl\lfloor\frac{n}{2}\Bigr\rfloor + 1.\]

    Otherwise, if \(n\) is composite and \[ k < n - \Bigl\lfloor\frac{n}{2}\Bigr\rfloor + 1,\] then Alice can choose her sequence so as to avoid any equal–sum partition and wins.

    Thus the final winning conditions are:

    Case 1: If \(n\) is prime, Bob wins if and only if \(k=n\); otherwise, Alice wins.
    Case 2: If \(n\) is composite, Bob wins if and only if \[ k \ge n - \Bigl\lfloor \frac{n}{2} \Bigr\rfloor + 1,\] otherwise, Alice wins.

Your program will process \(T\) test cases accordingly.

inputFormat

The first line contains an integer (T) (the number of test cases).

Each of the next (T) lines contains two space–separated integers (n) and (k) (with (2 \le k \le n)).

outputFormat

For each test case, output a single line containing either Alice or Bob, indicating the winner when both play optimally.

sample

2
2 2
3 2
Bob

Alice

</p>