A. The game of Osho

Codeforces
IDCF10114A
Time2000ms
Memory64MB
Difficulty
English · Original
Formal · Original
Faheem and Faheema love to play what they call the game of Osho, in this game they choose a number N randomly, the first player subtracts a non-zero number Bk1 less than or equal to N from N, then the second player subtracts number Bk2 (where B is given and ki is a non negative integer number), then again the first and so on until one of the players loses when he/she can't make any move. In other words, when it's a player's turn and N equals 0. For example let's see this game when B=2 and N=3. The first player Faheem can subtract 1 or 2 the optimal move here is 1, N now equals 2. In her turn Faheema subtract 2 because 1 will make Faheem win, Faheem now can't play any move and he loses. After a while they found that this game is boring so they decided to upgrade it, their version combines multiple subgames of the form (Bi, Ni) and the player can choose which of them he wants to play his move in, a player loses when he/she can't make a move. Given the subgames, your job is to determine which player wins the whole game assuming that both players play optimally. The first line contains T, the number of test cases. The next T lines contain G (1 ≤ G ≤ 100) the number of subgames and then follows G pairs of integers (1 ≤ Bi, Ni ≤ 1, 000, 000, 000) describing each subgame. For each test case print 1 if the first player wins the game, or 2 if the second wins. ## Input The first line contains T, the number of test cases. The next T lines contain G (1 ≤ G ≤ 100) the number of subgames and then follows G pairs of integers (1 ≤ Bi, Ni ≤ 1, 000, 000, 000) describing each subgame. ## Output For each test case print 1 if the first player wins the game, or 2 if the second wins. [samples]
**Definitions** Let $ T \in \mathbb{Z} $ be the number of test cases. For each test case, let $ G \in \mathbb{Z} $ be the number of subgames. Each subgame $ i \in \{1, \dots, G\} $ is defined by a pair $ (B_i, N_i) $, where: - $ B_i \in \mathbb{Z}^+ $ is the fixed subtractive step size. - $ N_i \in \mathbb{Z}_{\geq 0} $ is the initial pile size. **Constraints** 1. $ 1 \leq T \leq \text{unknown} $ (implied by input format) 2. For each test case: $ 1 \leq G \leq 100 $ 3. For each subgame $ i $: $ 1 \leq B_i, N_i \leq 10^9 $ **Objective** The game is an impartial combinatorial game composed of $ G $ independent subgames. In each subgame $ i $, a player may subtract any positive multiple of $ B_i $ that does not exceed the current pile size $ N_i $. A player loses when unable to move (all piles are 0). The Grundy number (nimber) for a subgame $ (B_i, N_i) $ is: $$ g_i = \left\lfloor \frac{N_i}{B_i} \right\rfloor \mod 2 $$ The overall game state is the XOR (nim-sum) of all subgame Grundy numbers: $$ S = \bigoplus_{i=1}^{G} g_i $$ If $ S \neq 0 $, the first player wins (output 1). If $ S = 0 $, the second player wins (output 2).
API Response (JSON)
{
  "problem": {
    "name": "A. The game of Osho",
    "description": {
      "content": "Faheem and Faheema love to play what they call the game of Osho, in this game they choose a number N randomly, the first player subtracts a non-zero number Bk1 less than or equal to N from N, then the",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 65536
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10114A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Faheem and Faheema love to play what they call the game of Osho, in this game they choose a number N randomly, the first player subtracts a non-zero number Bk1 less than or equal to N from N, then the...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ T \\in \\mathbb{Z} $ be the number of test cases.  \nFor each test case, let $ G \\in \\mathbb{Z} $ be the number of subgames.  \nEach subgame $ i \\in \\{1, \\dots, G\\} $ is defined by...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments