From c50ba64d232cdd8794bc2fd77e5bc431a35f25b8 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 3 Nov 2022 21:02:45 +0800 Subject: [PATCH] P3599 Koishi Loves Construction https://www.luogu.com.cn/record/92697061 --- Luogu/P3599/P3599.cpp | 76 ++++++++++++++++++++++++++++++++++++ Luogu/P3599/data/P3599_2.in | 3 ++ Luogu/P3599/data/P3599_2.out | 3 ++ 3 files changed, 82 insertions(+) create mode 100644 Luogu/P3599/P3599.cpp create mode 100644 Luogu/P3599/data/P3599_2.in create mode 100644 Luogu/P3599/data/P3599_2.out diff --git a/Luogu/P3599/P3599.cpp b/Luogu/P3599/P3599.cpp new file mode 100644 index 00000000..748e088c --- /dev/null +++ b/Luogu/P3599/P3599.cpp @@ -0,0 +1,76 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e5 + 5; + +int x, t, n, a[N]; + +bool is_prime(int x) { + if (x < 2) return false; + + for (int i = 2; i * i <= x; i++) { + if (x % i == 0) return false; + } + + return true; +} + +int binpow(int a, int b, int p) { + int res = 1; + + while (b) { + if (b & 1) res = 1ll * res * a % p; + a = 1ll * a * a % p; + b >>= 1; + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> x >> t; + + while (t--) { + cin >> n; + + if (n == 1) { + cout << 2 << ' ' << 1 << endl; + } else if (x == 1) { + if (n % 2 == 1) { + cout << 0 << endl; + } else { + cout << 2 << ' '; + + for (int i = 1; i <= n; i++) { + cout << (i % 2 ? n - i + 1 : i - 1) << ' '; + } + + cout << endl; + } + } else { // x == 2 + if (n == 2) { + cout << 2 << ' ' << "1 2" << endl; + } else if (n == 4) { + cout << 2 << ' ' << "1 3 2 4" << endl; + } else if (!is_prime(n)) { + cout << 0 << endl; + } else { + cout << 2 << ' ' << 1 << ' '; + + for (int i = 2; i < n; i++) { + cout << static_cast(i) * binpow(i - 1, n - 2, n) % n << ' '; + } + + cout << n << endl; + } + } + } + + return 0; +} diff --git a/Luogu/P3599/data/P3599_2.in b/Luogu/P3599/data/P3599_2.in new file mode 100644 index 00000000..ba4cbfe0 --- /dev/null +++ b/Luogu/P3599/data/P3599_2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2438196fcd99204a3871a90dd9a0f5bcd3c5d00d8f481b2481c023fdf6f04ad6 +size 63 diff --git a/Luogu/P3599/data/P3599_2.out b/Luogu/P3599/data/P3599_2.out new file mode 100644 index 00000000..fc3f0592 --- /dev/null +++ b/Luogu/P3599/data/P3599_2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d17b5ea76f4a807d7aa2523bc46e20ba7a966a421192f51be462836c47c66ba3 +size 20