From be64640ada8f43b577c053f81a0e01416803d99f Mon Sep 17 00:00:00 2001 From: Kirito <1362050620@qq.com> Date: Wed, 12 Oct 2016 11:28:27 +0800 Subject: [PATCH] Create 1842_x7536110.cpp --- QUSTOJ/1842_x7536110.cpp | 126 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 QUSTOJ/1842_x7536110.cpp diff --git a/QUSTOJ/1842_x7536110.cpp b/QUSTOJ/1842_x7536110.cpp new file mode 100644 index 0000000..fc4ea44 --- /dev/null +++ b/QUSTOJ/1842_x7536110.cpp @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +#include +#include +#include +using namespace std; +#define mod 1004535809LL +#define G 3LL +#define maxn 455555 + +long long x1[maxn], x2[maxn]; +long long qpow (long long a, long long b) { + long long ret=1; + while (b) { + if (b&1) ret = (ret*a)%mod; + a = (a*a)%mod; + b >>= 1; + } + return ret; +} + +void change (long long *y, int len) { + int i, j, k; + for(i = 1, j = len / 2; i < len - 1; i++) { + if (i < j) swap(y[i], y[j]); + k = len / 2; + while (j >= k) { + j -= k; + k /= 2; + } + if (j < k) j += k; + } +} + +void ntt (long long *y, int len, int on) { + change (y, len); + int id = 0; + for(int h = 2; h <= len; h <<= 1) { + id++; + long long wn = qpow (G, (mod - 1) / (1<> 1; + solve (l, mid); + int len = 1; + while (len <= r-l+1) {len <<= 1;} + for (int i = 0; i < len; i++) { + x1[i] = x2[i] = 0; + } + for (int i = l; i <= mid; i++) { + x1[i-l] = f[i]*rev[i]%mod; + } + for (int i = 1; i <= r-l; i++) { + x2[i-1] = h[i]*rev[i-1]%mod; + } + ntt (x1, len, 1), ntt (x2, len, 1); + for (int i = 0; i < len; i++) x1[i] = x1[i] * x2[i] % mod; + ntt (x1, len, -1); + for (int i = mid+1; i <= r; i++) { + f[i] += x1[i-l-1]*fac[i-1] %mod; + f[i] %= mod; + } + //cout << l << " " << r << endl; + //for (int i = 1; i <= 4; i++) cout << f[i] << " "; cout << endl; + solve (mid+1, r); +} + +int main () { + // freopen ("in", "r", stdin); + // freopen ("out", "w", stdout); + // //int t1 = clock (); + g[1] = h[1] = 1; + for (int i = 2; i <= 200000; i++) { + h[i] = qpow (i, i-2); + g[i] = qpow (2, 1LL*i*(i-1)/2); + } + fac[0] = 1; + for (int i = 1; i <= 200000; i++) fac[i] = fac[i-1] * i % mod; + rev[200000] = qpow (fac[200000], mod - 2); + for (int i = 200000-1; i >= 0; i--) rev[i] = rev[i+1] * (i+1) % mod; + int t; + scanf ("%d", &t); + while (t--) { + scanf ("%lld", &n); + memset (f, 0, sizeof f); + solve (1, n); + long long ans = g[n]-f[n]; + (ans %= mod) += mod; ans %= mod; + printf ("%lld\n", ans); + } + //int t2 = clock (); + //cout << t2-t1 << endl; + return 0; +}