template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
int T, a[N], vis[N], tmp[N];
inlineboolcheck_sum(int x){ memset(vis, 0, sizeof vis); tmp[0] = 0; for (int i = 1; i <= x; ++ i) { tmp[i] = tmp[i - 1] + a[i]; if (vis[tmp[i] % x]) returnfalse; vis[tmp[i] % x] = 1; } returntrue; }
inlineboolcheck_mul(int x){ memset(vis, 0, sizeof vis); tmp[0] = 1; for (int i = 1; i <= x; ++ i) { tmp[i] = tmp[i - 1] * a[i]; if (vis[tmp[i] % x]) returnfalse; vis[tmp[i] % x] = 1; } returntrue; }
inlinevoidsolve(int x){ for (int i = 1; i <= x; ++ i) a[i] = i; printf("NOW: %d\n", x); int flag = 0; do { if (check_sum(x)) { printf(" SUM: YES\n "); flag = 1; for (int i = 1; i <= x; ++ i) printf("%d ", a[i]); printf("\n "); for (int i = 1; i <= x; ++ i) printf("%d ", tmp[i]); printf("\n "); for (int i = 1; i <= x; ++ i) printf("%d ", tmp[i] % x); puts(""); } } while (next_permutation(a + 1, a + x + 1)); if (!flag) puts(" SUM: NO"); flag = 0; for (int i = 1; i <= x; ++ i) a[i] = i; do { if (check_mul(x)) { printf(" MUL: YES\n "); flag = 1; for (int i = 1; i <= x; ++ i) printf("%d ", a[i]); printf("\n "); for (int i = 1; i <= x; ++ i) printf("%d ", tmp[i]); printf("\n "); for (int i = 1; i <= x; ++ i) printf("%d ", tmp[i] % x); puts(""); } } while (next_permutation(a + 1, a + x + 1)); if (!flag) puts(" MUL: NO"); puts("--------------------------"); }
intmain(){ freopen("brute.txt", "w", stdout); read(T); int i = 0; while (++ i <= T) solve(i); return (0 - 0); }
template <typename T> inlinevoidread(T &x){ x = 0; int f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = -f; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; x *= f; }
int x, t, n, prm[N], nprm[N], pcnt;
inlinevoideuler(int x){ for (int i = 2; i <= x; ++ i) { if (!nprm[i]) prm[++ pcnt] = i; for (int p = 1; p <= pcnt; ++ p) if (prm[p] * i <= x) { nprm[prm[p] * i] = true; if (i & prm[p] == 0) break; } elsebreak; } }
inlineintfpow(int x, int p){ int res = 1; while (p) { if (p & 1) res = 1ll * res * x % n; p >>= 1; x = 1ll * x * x % n; } return res; }
inlinevoidtask1(){ read(n); if (n == 1) {puts("2 1"); return;} if (n & 1) {puts("0"); return;} printf("2 %d %d ", n, n - 1); for (int i = 1; i <= n / 2 - 1; ++ i) printf("%d %d ", i << 1, n - 1 - (i << 1)); }
inlinevoidtask2(){ read(n); if (n == 1) {puts("2 1"); return;} if (n == 4) {puts("2 1 3 2 4"); return;} if (nprm[n]) {puts("0"); return;} printf("2 "); int now = 1, mul = 1; for (int i = 1; i < n; ++ i) { printf("%d ", now); now = 1ll * (i + 1) * fpow(mul, n - 2) % n; mul = 1ll * mul * now % n; } printf("%d\n", n); }
intmain(){ read(x), read(t); if (x == 1) while (t --) task1(); else {euler(1e5); while (t --) task2();} return (0 - 0); }