1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| # include <bits/stdc++.h>
# define R register # define ll long long
const ll MaxN = 1e5 + 10; ll n, tp, flag, p[MaxN];
ll check(ll x) { for(ll i = 2; i * i <= x; i++) if(x % i == 0) return 1; return 0; }
ll exgcd(ll a, ll b, ll &x, ll &y) { ll g = a; if(b == 0) x = 1, y = 0; else g = exgcd(b, a % b, y, x), y -= (a / b) * x; return g; }
signed main() { scanf("%lld", &n); if(n == 1) puts("YES\n1\n"); else if(n == 4) puts("YES\n1 3 2 4"); else if(check(n)) puts("NO"); else { printf("YES\n1 "); for(ll i = 2; i < n; i++) { ll x, y; exgcd(i - 1, n, x, y); printf("%lld ", ((x * 1ll * i) % n + n) % n); } printf("%lld\n", n); } return 0; }
|