CF487C.Prefix Product Sequence
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider a sequence [_a_1, _a_2, ... , a__n]. 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].
考虑一个序列 a1, a2, ..., an。定义其前缀积序列为
。
现给定 n,请找出 [1, 2, ..., n] 的一个排列,使得其前缀积序列是 [0, 1, ..., n − 1] 的一个排列。
输入格式
The only input line contains an integer n (1 ≤ n ≤ 105).
唯一的一行输入包含一个整数 n(1 ≤ n ≤ 105)。
输出格式
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 a__i. 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.
在第一行输出中,如果存在这样的序列,则输出 “YES”;如果不存在这样的序列,则输出 “NO”。
如果存在解,则还需输出 n 行。第 i 行仅包含一个整数 a__i。该序列中的元素应为互不相同的正整数,且均不超过 n。
若存在多个解,输出其中任意一个即可。
输入输出样例
输入#1
7
输出#1
YES 1 4 3 6 5 2 7
输入#2
6
输出#2
NO
说明/提示
For the second sample, there are no valid sequences.
对于第二个样例,不存在有效的序列。
输入解题思路,AI测评打分。不知道怎么写?