atcoder#ARC118D. [ARC118D] Hamiltonian Cycle

[ARC118D] Hamiltonian Cycle

Score : 700700 points

Problem Statement

Given are a prime number PP and positive integers aa and bb. Determine whether there is a sequence of PP integers, A=(A1,A2,,AP)A = (A_1, A_2, \ldots, A_P), satisfying all of the conditions below, and print one such sequence if it exists.

  • 1AiP11\leq A_i\leq P - 1.
  • A1=AP=1A_1 = A_P = 1.
  • (A1,A2,,AP1)(A_1, A_2, \ldots, A_{P-1}) is a permutation of (1,2,,P1)(1, 2, \ldots, P-1).
  • For every 2iP2\leq i\leq P, at least one of the following holds.- AiaAi1(modP)A_{i} \equiv aA_{i-1}\pmod{P}
    • Ai1aAi(modP)A_{i-1} \equiv aA_{i}\pmod{P}
    • AibAi1(modP)A_{i} \equiv bA_{i-1}\pmod{P}
    • Ai1bAi(modP)A_{i-1} \equiv bA_{i}\pmod{P}
  • AiaAi1(modP)A_{i} \equiv aA_{i-1}\pmod{P}
  • Ai1aAi(modP)A_{i-1} \equiv aA_{i}\pmod{P}
  • AibAi1(modP)A_{i} \equiv bA_{i-1}\pmod{P}
  • Ai1bAi(modP)A_{i-1} \equiv bA_{i}\pmod{P}

Constraints

  • 2P1052\leq P\leq 10^5
  • PP is a prime.
  • 1a,bP11\leq a, b \leq P - 1

Input

Input is given from Standard Input in the following format:

PP aa bb

Output

If there is an integer sequence AA satisfying the conditions, print Yes; otherwise, print No. In the case of Yes, print the elements in your sequence AA satisfying the requirement in the next line, with spaces in between.

A1A_1 A2A_2 \ldots APA_P

If multiple sequences satisfy the requirement, any of them will be accepted.

13 4 5
Yes
1 5 11 3 12 9 7 4 6 8 2 10 1

This sequence satisfies the conditions, since we have the following modulo P=13P = 13:

  • A25A1A_2\equiv 5A_1
  • A24A3A_2\equiv 4A_3
  • \vdots
  • A134A12A_{13}\equiv 4A_{12}
13 1 2
Yes
1 2 4 8 3 6 12 11 9 5 10 7 1
13 9 3
No
13 1 1
No