Codeforces 487C Prefix Product Sequence[数论+构造]

首先第一个必须放1(不然放在中间会有两个重复的数) 最后一个必须放n (n! equiv 0 pmod n)

Codeforces 487C Prefix Product Sequence[数论+构造]

[ ext{中间的数放}frac{2}{1},frac{3}{2},... ]

这样第 (i) 个数就是 $$
prod_{j=1}^i{a_j}=1 imes frac{2}{1} imes frac{3}{2} imes ...=i

[ 现在前缀积各不相同了,如何证明每个元素不同呢?发现中间的数减去1都是1/x的形式,因为逆元互不相同(百度百科:群G中任意一个元素a,都在G中有唯一的逆元a‘,具有性质aa'=a'a=e,其中e为群的单位元。),所以每个元素也是不同的 ```cpp namespace QvvQ { int mod; struct Mod { int a; Mod(int _a) : a(_a) {} Mod(ll _a) : a(_a % mod) {} Mod() {} int inv() {return Pow(a, mod - 2, mod);} Mod &operator += (const int b) {a += b; if (a < 0) a += mod; else if (a >= mod) a -= mod; return *this;} Mod &operator -= (const int b) {a -= b; if (a < 0) a += mod; else if (a >= mod) a -= mod; return *this;} Mod &operator *= (const int b) {a = a * 1ll * b % mod; if (a < 0) a += mod; return *this;} Mod &operator /= (const int b) {a = a * 1ll * Pow(b, mod - 2, mod) % mod; if (a < 0) a += mod; return *this;} Mod &operator += (const Mod rhs) {return *this += rhs.a;} Mod &operator -= (const Mod rhs) {return *this -= rhs.a;} Mod &operator *= (const Mod rhs) {return *this *= rhs.a;} Mod &operator /= (const Mod rhs) {return *this /= rhs.a;} friend Mod operator + (Mod c, const Mod rhs) {return c += rhs.a;} friend Mod operator - (Mod c, const Mod rhs) {return c -= rhs.a;} friend Mod operator * (Mod c, const Mod rhs) {return c *= rhs.a;} friend Mod operator / (Mod c, const Mod rhs) {return c /= rhs.a;} Mod &operator = (const int x) {a = x; return *this;} Mod &operator = (const ll x) {a = x % mod; return *this;} Mod &operator = (const Mod rhs) {a = rhs.a; return *this;} } inv[N]; void init() { } void solve() { int n = in; mod = n; if (n == 1) { out, "YES 1"; return ; } if (n == 4) { out, "YES 1 3 2 4"; return ; } for (int i = 2; i * i <= n; ++i) if (n % i == 0) return puts("NO"), void(); puts("YES"); inv[0] = inv[1] = 1; lo(i, 2, n) inv[i] = (n - n / i) * inv[n % i]; lo1(i, n-1) out, (inv[i - 1] * i).a, ' '; out, n; } } ```]