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.

Example

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.

要求给出1~n的排列,使得前1,2...n项之积模n恰好包含[0,n-1]中所有数

显然n要放最后,不然乘个n之后后面的积都是0了(不过这句话好像并没有卵用)

显然[0,n-1]每个数不能出现超过1次(好像也没有卵用)

如果n是质数,非常简单,令模n之后分别是1,2,3,4...n-1,0,

倒推可知第一个数是1,第二个数是2乘(1关于n的逆元),第三个数是3乘(2关于n的逆元)……最后一个是n

如果n不是质数,,,太恶心了

先给结论:如果n==4,发现有一解1,3,2,4是可以的,否则不行。

证明:当n为合数且n!=4,不妨假设n=p*q(p>2,p>=q)

那么1~pq当中有至少三个不同的数q,2q,pq。

显然n=pq是一定要放在排列最后的,再分类讨论:

p==q,n=p^2,而且p,2p的位置要在在p^2之前,显然p*2p=2p^2=2n,所以在p处,或者2p处前k项的积就是0了,p^2处也是0,显然不行

p!=q,p和q都在pq之前,同理,在p处,或者q处前k项的积是pq的倍数,所以也是0,而pq处也是0,也不行

*所以只有p==q==2的时候,没有p和2p同时出现,所以找到了一组解

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<ctime>
#define LL long long
#define inf 0x7ffffff
#define pa pair<int,int>
#define mkp(a,b) make_pair(a,b)
#define pi 3.1415926535897932384626433832795028841971
#define mod 100007
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n;
LL ni[];
inline LL quickpow(LL a,int b)
{
LL s=;
while (b)
{
if (b&)s=(s*a)%n;
a=(a*a)%n;
b>>=;
}
return s;
}
int main()
{
n=read();
if (n==){puts("YES\n1");return ;}
if (n==){puts("YES\n1\n3\n2\n4\n");return ;}
for (int i=;i<=sqrt(n);i++)if (n%i==){puts("NO");return ;}
for (int i=;i<n;i++)ni[i]=quickpow(i,n-);
puts("YES");
puts("");
for (int i=;i<n;i++)printf("%d\n",i*ni[i-]%n);
printf("%d\n",n);
}

cf487C

cf487C Prefix Product Sequence的更多相关文章

  1. Codeforces 487C. Prefix Product Sequence 逆+结构体

    意甲冠军: 对于数字n, 他询问是否有1~n置换 这种布置能够在产品上模每个前缀n 有可能0~n-1 解析: 通过观察1肯定要在首位,n一定要在最后 除4意外的合数都没有解 其它质数构造 a[i]=i ...

  2. codeforces 487C C. Prefix Product Sequence(构造+数论)

    题目链接: C. Prefix Product Sequence time limit per test 1 second memory limit per test 256 megabytes in ...

  3. Codeforces.487C.Prefix Product Sequence(构造)

    题目链接 \(Description\) 对于一个序列\(a_i\),定义其前缀积序列为\(a_1\ \mathbb{mod}\ n,\ (a_1a_2)\ \mathbb{mod}\ n,...,( ...

  4. Prefix Product Sequence CodeForces - 487C (数论,构造)

    大意: 构造一个[1,2,...n]的排列, 使得前缀积模n为[0,1,...,n-1]的排列 这种构造都好巧妙啊, 大概翻一下官方题解好了 对于所有>=6的合数$n$, 有$(n-1)! \e ...

  5. 487C Prefix Product Sequence

    传送门 题目大意 分析 因为n为质数所以i-1的逆元唯一 因此ai唯一 代码 #include<iostream> #include<cstdio> #include<c ...

  6. [CF 487C Prefix Product Sequence]

    题意 将1~n的正整数重排列,使得它的前缀积在模n下形成0~n-1的排列,构造解或说明无解.n≤1E5. 思考 小范围内搜索解,发现n=1,n=4和n为质数时有解. 不难发现,n一定会放在最后,否则会 ...

  7. codeforces 练习

    codeforces 627 D. Preorder Test 二分 + 树dp 做logn次树dp codeforces 578D.LCS Again 给出一个字符串str,长度n<=10^6 ...

  8. Subarray Product Less Than K LT713

    Your are given an array of positive integers nums. Count and print the number of (contiguous) subarr ...

  9. Adding Pagination 添加分页

    本文来自: http://www.bbsmvc.com/MVC3Framework/thread-206-1-1.html You can see from Figure 7-16 that all ...

随机推荐

  1. MySQL 导出一句话

    听说是很老的东西了,学习的时候发现还是很好用的,故学习转载过来,留备学习. mysql 导出一句话 方法1:网上流行的方法 流程:(1)建表--->(2)插入数据--->(3)select ...

  2. maven打包错误:No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?

    [INFO] Scanning for projects...[INFO]                                                                ...

  3. 打通C/4HANA和S/4HANA的一个原型开发:智能服务创新案例

    今年6月SAP发布C/4HANA之后,有顾问朋友们在微信公众号后台留言,询问C/4HANA如何同SAP的数字化核心S/4HANA系统结合起来,从而打通企业的前后端业务,帮助企业实现数字化转型. 有的顾 ...

  4. 第009课 gcc和arm-linux-gcc和MakeFile

    from:第009课 gcc和arm-linux-gcc和MakeFile 第001节_gcc编译器1_gcc常用选项_gcc编译过程详解 gcc的使用方法 gcc [选项] 文件名 gcc常用选项 ...

  5. 爬虫_python3_requests_2

    pip install requests 进行简单的操作 发送一个get请求 # 发送请求 import requests response = requests.get('http://httpbi ...

  6. 电脑上文件的后缀名被隐藏,把一个文本文件改成.bat时,默认打开的还是文本。

    1.打开文件夹,选择组织,点击“文件夹和搜索选项”,如图: 2.选择“查看”,找到“隐藏已知文件类型的扩展名”,不要勾选这一项,如图: 3.点击“确定”或者“应用”

  7. servlet上传多个文件(乱码解决)

    首先,建议将编码设置为GB2312,并在WEB-INF\lib里导入:commons-fileupload-1.3.jar和commons-io-2.4.jar, 可百度下下载,然后你编码完成后,上传 ...

  8. DP玄学优化——斜率优化

    --以此博客来悼念我在\(QBXT\)懵逼的时光 \(rqy\; tql\) (日常%\(rqy\)) 概念及用途 斜率优化是\(DP\)的一种较为常用的优化(据说在高中课本里稍有提及),它可以用于优 ...

  9. Fisherfaces 算法的具体实现源码

    /* * Copyright (c) 2011. Philipp Wagner <bytefish[at]gmx[dot]de>. * Released to public domain ...

  10. ubuntu 安装 php7.2

    sudo apt-get install software-properties-common python-software-properties sudo add-apt-repository p ...