Consider a sequence [a1, a2, ... , an]. Define its prefix product sequence <image>. Now…
- User
Consider a sequence [a1, a2, ... , an]. Define its prefix product sequence .
Now given n, find a permutation of [1, 2, ..., n], such that its prefix product sequence is a permutation of [0, 1, ..., n - 1]. Input
The only input line contains an integer n (1 ≤ n ≤ 105).
Output
In the first output line, print "YES" if such sequence exists, or print "NO" if no such sequence exists.
If any solution exists, you should output n more lines. i-th line contains only an integer ai. The elements of the sequence should be different positive integers no larger than n.
If there are multiple solutions, you are allowed to print any of them.
Examples
Input
7
Output
YES 1 4 3 6 5 2 7
Input
6
Output
NO
Note
For the second sample, there are no valid sequences.
Assistant
Okay, let's try to now design the algorithm.
First, we need to determine if n is valid. The conditions are:
- n =1,4, or a prime number.
Thus, the first task is to check if n is a prime,4, or 1.
But checking if n is a prime for n up to 1e5 is manageable.
To implement this:
First, handle edge cases:
if n ==1, output YES and just the list '1'.
if n ==4: then the permutation is [1,3,2,4].
else:
if n is a prime:
proceed to construct the permutation.
else:
output NO.
Thus the first part is approvoing thru the cases:
Now, for constructing the permutation when n is prime:
We need an efficient way to generate the sequence.
But how?
The constructive approach that seems has the best chance is to:
start with the first element as1.
Then, the随后的 elements are arbitrary except for the statistically likely that the greedy approach w工作.
But it's computationally intensive for large n.
Perhaps
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.