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
pythondef is_prime(n): if n <= 1: return False if n == 2: return True if n % 2 == 0: return False for i in range(3, int(n**0.5) + 1, 2): if n % i == 0: return False return True n = int(input()) if n == 1: print("YES") print(1) elif n == 4: print("YES") print(1) print(3) print(2) print(4) else: if not is_prime(n): print("NO") else: print("YES") elements = [1] for i in range(2, n): inv_prev = pow(i-1, n-2, n) current = (i * inv_prev) % n elements.append(current) elements.append(n) for num in elements: print(num)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.