G. Game of Primes

Codeforces
IDCF10282G
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Alice and Bob always like playing games with each other and today they found a new game about primes. There are two positive integers $x$ and $y$ in the game, and Alice and Bob move in turn. At each turn, the current player can choose one integer and subtract it by $1$ (making $(x, y)$ to $(x -1, y)$ or to $(x, y -1)$). The game ends when one of following conditions is met and the winner is specified at the same time: Now $x$, $y$, $K$ and who moves first are given, can you determine who will finally win the game if they both play optimally? The first line of input contains an integer $T$, representing the number of test cases. Then following $T$ lines and each line contains one test case. For each test case, there are four integers $x$, $y$, $K$ and $w$ separated by exactly one space. $x$,$y$,$K$ are mentioned above. $w = 0$ when Alice moves first and $w = 1$ when Bob moves first. For each test case, you should output *Case $x$: name* in one line, where $x$ indicates the case number starting from 1, and *name* is the player who will win the game. $1 <= T <= 100$ $2 <= x, y <= 10^6$ $2 <= K <= min (x, y)$ $0 <= w <= 1$ For $90 %$ test cases: $max (x, y) <= 1000$ ## Input The first line of input contains an integer $T$, representing the number of test cases. Then following $T$ lines and each line contains one test case.For each test case, there are four integers $x$, $y$, $K$ and $w$ separated by exactly one space. $x$,$y$,$K$ are mentioned above. $w = 0$ when Alice moves first and $w = 1$ when Bob moves first. ## Output For each test case, you should output *Case $x$: name* in one line, where $x$ indicates the case number starting from 1, and *name* is the player who will win the game. [samples] ## Note $1 <= T <= 100$$2 <= x, y <= 10^6$$2 <= K <= min (x, y)$$0 <= w <= 1$For $90 %$ test cases: $max (x, y) <= 1000$
**Definitions** Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of positive integers. For any subarray $ x = (a_i, a_{i+1}, \dots, a_j) $ with $ 1 \le i \le j \le n $, define $ \psi(x) $ as the number of subsets $ I \subseteq \{i, i+1, \dots, j\} $ such that $$ \sum_{k \in I} (-a_k) + \sum_{k \in \{i,\dots,j\} \setminus I} a_k = 0. $$ Equivalently, $ \psi(x) $ is the number of ways to assign signs $ \pm 1 $ to each element of $ x $ such that the signed sum is zero, with the constraint that the original values are positive. Let $ S $ be the set of all contiguous non-empty subarrays of $ A $: $$ S = \{ (a_i, a_{i+1}, \dots, a_j) \mid 1 \le i \le j \le n \}. $$ **Constraints** 1. $ 1 \le n \le 1000 $ 2. $ 1 \le a_i \le 1000 $ for all $ i \in \{1, \dots, n\} $ 3. $ \sum_{i=1}^n a_i \le 10000 $ **Objective** Compute $$ \sum_{x \in S} \psi(x) \mod (10^9 + 7) $$
API Response (JSON)
{
  "problem": {
    "name": "G. Game of Primes",
    "description": {
      "content": "Alice and Bob always like playing games with each other and today they found a new game about primes. There are two positive integers $x$ and $y$ in the game, and Alice and Bob move in turn. At each ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10282G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Alice and Bob always like playing games with each other and today they found a new game about primes.\n\nThere are two positive integers $x$ and $y$ in the game, and Alice and Bob move in turn. At each ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of positive integers.  \nFor any subarray $ x = (a_i, a_{i+1}, \\dots, a_j) $ with $ 1 \\le i \\le j \\le n $, define $ \\psi(x) $ as the n...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments