atcoder#ARC118D. [ARC118D] Hamiltonian Cycle
[ARC118D] Hamiltonian Cycle
Score : points
Problem Statement
Given are a prime number and positive integers and . Determine whether there is a sequence of integers, , satisfying all of the conditions below, and print one such sequence if it exists.
- .
- .
- is a permutation of .
- For every , at least one of the following holds.-
Constraints
- is a prime.
Input
Input is given from Standard Input in the following format:
Output
If there is an integer sequence satisfying the conditions, print Yes
; otherwise, print No
.
In the case of Yes
, print the elements in your sequence satisfying the requirement in the next line, with spaces in between.
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 :
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