B. Divples

Codeforces
IDCF10230B
Time2000ms
Memory64MB
Difficulty
English · Original
Formal · Original
After your death, you're sent to a mysterious room. There are two guardian cats and two doors, one goes to heaven of AC problems and another goes to hell NO. One cat likes all divisors of an integer a and the other cat likes all multiples of an integer b. You where asked to write all integers that satisfies both. If you answer correctly, you may go to heaven of AC problems, full of balloons, otherwise you're sent to hell NO. The input consists of two integers a and b, where 1 ≤ b ≤ a ≤ 1012. The output consists of one line with all integers from smallest to largest that satisfies both guardian cats. ## Input The input consists of two integers a and b, where 1 ≤ b ≤ a ≤ 1012. ## Output The output consists of one line with all integers from smallest to largest that satisfies both guardian cats. [samples]
**Definitions** Let $ n, k \in \mathbb{Z} $ with $ 1 \leq n, k \leq 10^{18} $. Let $ S_n $ be the sequence of moves generated by the brute-force Hanoi Tower algorithm for $ n $ disks, where each move is represented as a string of the form "disk from peg A to peg B". **Constraints** 1. $ 1 \leq n, k \leq 10^{18} $ 2. The total number of moves in $ S_n $ is $ 2^n - 1 $. **Objective** For each test case: - If $ k > 2^n - 1 $, output `"Orz"`. - Otherwise, output the $ k $-th move in $ S_n $, where moves are ordered by execution in the standard recursive Hanoi algorithm: The $ i $-th move (1-indexed) corresponds to moving disk $ d $ from source to target, where: $$ d = \nu_2(i) + 1, \quad \text{and the direction is determined by parity of } n \text{ and } d $$ Specifically, for disk $ d $, its movement cycle is periodic with period $ 2^d $, and the direction alternates based on $ n \mod 2 $ and $ d \mod 2 $. The source and target pegs for the $ i $-th move can be computed via: Let $ d = \nu_2(i) + 1 $, and let $ r = \left\lfloor \frac{i - 1}{2^d} \right\rfloor \mod 3 $. Then: - If $ n $ is even: - $ d $ odd: cycle $ A \to C \to B \to A $ - $ d $ even: cycle $ A \to B \to C \to A $ - If $ n $ is odd: - $ d $ odd: cycle $ A \to B \to C \to A $ - $ d $ even: cycle $ A \to C \to B \to A $ The peg sequence for disk $ d $ is determined by the above cycle, indexed by $ r $. Output the move as: `"disk d from X to Y"` where $ X, Y $ are the source and target pegs from the cycle.
API Response (JSON)
{
  "problem": {
    "name": "B. Divples",
    "description": {
      "content": "After your death, you're sent to a mysterious room. There are two guardian cats and two doors, one goes to heaven of AC problems and another goes to hell NO. One cat likes all divisors of an integer a",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 65536
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10230B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "After your death, you're sent to a mysterious room. There are two guardian cats and two doors, one goes to heaven of AC problems and another goes to hell NO. One cat likes all divisors of an integer a...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, k \\in \\mathbb{Z} $ with $ 1 \\leq n, k \\leq 10^{18} $.  \nLet $ S_n $ be the sequence of moves generated by the brute-force Hanoi Tower algorithm for $ n $ disks, where each m...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments