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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
| void exprinv(Expr res, Expr a, int lim) { static Expr b, a0; int n, len, i;
assert(a[0]); b[0] = qpow(a[0], MOD - 2); n = 1; while (n < lim) { len = n << 2; copy(a0, a, n << 1);
initrev(len);
dft(b, len); dft(a0, len); for (i = 0; i < len; i++) b[i] = b[i] * (2 - 1ll * a0[i] * b[i] % MOD + MOD) % MOD; idft(b, len);
for (i = n << 1; i < len; i++) b[i] = 0;
memset(a0, 0, len << 2);
n <<= 1; } memcpy(res, b, lim << 2); memset(b, 0, len << 2); } void exprsqrt(Expr res, Expr a, int lim) { static Expr b, a0, invb; int n, len, i;
b[0] = modsqrt(a[0]); n = 1; while (n < lim) { len = n << 2; copy(a0, a, n << 1); exprinv(invb, b, n << 1);
initrev(len);
dft(b, len); dft(invb, len); dft(a0, len); for (i = 0; i < len; i++) b[i] = (b[i] + 1ll * a0[i] * invb[i]) % MOD; idft(b, len);
for (i = 0; i < len; i++) b[i] = 1ll * b[i] * INV2 % MOD; for (i = n << 1; i < len; i++) b[i] = 0;
n <<= 1; } memcpy(res, b, lim << 2); memset(b, 0, len << 2); memset(a0, 0, len << 2); memset(invb, 0, len << 2); } void exprdet(Expr res, Expr a, int lim) { int i;
for (i = 1; i < lim; i++) res[i - 1] = 1ll * a[i] * i % MOD; res[lim - 1] = 0; } void exprint(Expr res, Expr a, int lim) { int i;
for (i = lim - 1; ~i; i--) res[i] = 1ll * a[i - 1] * qpow(i, MOD - 2) % MOD; res[0] = 0; } void exprln(Expr res, Expr a, int lim) { static Expr inva; int i, len = lim << 1;
exprinv(inva, a, lim); exprdet(res, a, lim); initrev(len); dft(res, len); dft(inva, len); for (i = 0; i < len; i++) res[i] = 1ll * res[i] * inva[i] % MOD; idft(res, len); exprint(res, res, len); for (i = lim; i < len; i++) res[i] = 0;
memset(inva, 0, len << 2); } void exprexp(Expr res, Expr a, int lim) { static Expr b, lnb; int n, len, i;
assert(a[0] == 0); b[0] = 1; n = 1; while (n < lim) { len = n << 2; exprln(lnb, b, n << 1); for(i=0; i<n<<1; i++) qmod(lnb[i] = MOD + a[i] - lnb[i]); qmod(lnb[0] = lnb[0] + 1);
initrev(len);
dft(b, len); dft(lnb, len); for (i = 0; i < len; i++) b[i] = 1ll * b[i] * lnb[i] % MOD; idft(b, len);
for (i = n << 1; i < len; i++) b[i] = 0;
n <<= 1; } memcpy(res, b, lim << 2); memset(b, 0, len << 2); memset(lnb, 0, len << 2); }
|