• 「多项式指数函数」


    「多项式指数函数」

    前置知识

    导数

    微积分

    多项式牛顿迭代

    基本问题

    给定一个 (n) 次多项式 (A(x)),求 (B(x)) 满足

    [B(x)equiv e^{A(x)}mod x^n ]

    两遍同时用 (ln) 取对数

    [ln^{B(x)}equiv A(x)mod x^n ]

    [ln^{B(x)} - A(x)equiv 0mod x^n ]

    套用牛顿迭代,设

    [G(B_0(x))=ln^{B(x)} - A(x) ]

    [B(x)=B_0(x) - frac{G(B_0(x))}{G'(B_0(x))} ]

    由于 (A(x)) 是常数,所以直接消掉不影响求导

    [G'(B_0(x))=frac{1}{B(x)} ]

    [B(x)=B_0(x) - frac{ln^{B_0(x)} - A(x)}{frac{1}{B_0(x)}} ]

    [B(x)=B_0(x) - B_0(x)ln^{B_0(x)} + B_0(x)A(x) ]

    [B(x)=B_0(x)(1 - ln^{B_0(x)} + A(x)) ]

    最后递归求解即可

    代码
    #include <cstdio>
    #include <cstring>
    #include <iostream>
    #include <algorithm>
    
    typedef long long ll;
    typedef unsigned long long ull;
    
    using namespace std;
    
    const int maxn = 3e5 + 50, INF = 0x3f3f3f3f, mod = 998244353, inv3 = 332748118;
    
    inline int read () {
    	register int x = 0, w = 1;
    	register char ch = getchar ();
    	for (; ch < '0' || ch > '9'; ch = getchar ()) if (ch == '-') w = -1;
    	for (; ch >= '0' && ch <= '9'; ch = getchar ()) x = x * 10 + ch - '0';
    	return x * w;
    }
    
    inline void write (register int x) {
    	if (x / 10) write (x / 10);
    	putchar (x % 10 + '0');
    }
    
    int n;
    int f[maxn];
    int f0[maxn], rf0[maxn], nf0[maxn], lnf0[maxn];
    int res[maxn], tmp[maxn], rev[maxn];
    
    inline int qpow (register int a, register int b, register int ans = 1) {
    	for (; b; b >>= 1, a = 1ll * a * a % mod)
    		if (b & 1) ans = 1ll * ans * a % mod;
    	return ans;
    }
    
    inline void NTT (register int len, register int * a, register int opt) {
    	for (register int i = 1; i < len; i ++) if (i < rev[i]) swap (a[i], a[rev[i]]);
    	for (register int d = 1; d < len; d <<= 1) {
    		register int w1 = qpow (opt, (mod - 1) / (d << 1));
    		for (register int i = 0; i < len; i += d << 1) {
    			register int w = 1;
    			for (register int j = 0; j < d; j ++, w = 1ll * w * w1 % mod) {
    				register int x = a[i + j], y = 1ll * w * a[i + j + d] % mod;
    				a[i + j] = (x + y) % mod, a[i + j + d] = (x - y + mod) % mod;
    			}
    		}
    	}
    }
    
    inline void Poly_Inv (register int d, register int * a, register int * b) {
    	if (d == 1) return b[0] = qpow (a[0], mod - 2), void ();
    	Poly_Inv ((d + 1) >> 1, a, b);
    	register int len = 1, bit = 0;
    	while (len < (d << 1)) len <<= 1, bit ++;
    	for (register int i = 0; i < len; i ++) res[i] = 0, rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << bit - 1);
    	for (register int i = 0; i < d; i ++) res[i] = a[i];
    	NTT (len, res, 3), NTT (len, b, 3);
    	for (register int i = 0; i < len; i ++) b[i] = ((2ll * b[i] % mod - 1ll * res[i] * b[i] % mod * b[i] % mod) % mod + mod) % mod;
    	NTT (len, b, inv3);
    	register int inv = qpow (len, mod - 2);
    	for (register int i = 0; i < d; i ++) b[i] = 1ll * b[i] * inv % mod; for (register int i = d; i < len; i ++) b[i] = 0;
    }
    
    inline void Poly_Ln (register int d, register int * f0, register int * lnf0) {
    	register int len = 1, bit = 0;
    	while (len < (d << 1)) len <<= 1, bit ++;
    	for (register int i = 0; i < len; i ++) rf0[i] = nf0[i] = lnf0[i] = 0, rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << bit - 1);
    	for (register int i = 0; i < d; i ++) rf0[i] = 1ll * f0[i + 1] * (i + 1) % mod;
    	Poly_Inv (d, f0, nf0);
    	NTT (len, rf0, 3), NTT (len, nf0, 3);
    	for (register int i = 0; i < len; i ++) lnf0[i] = 1ll * rf0[i] * nf0[i] % mod;
    	NTT (len, lnf0, inv3);
    	register int inv = qpow (len, mod - 2);
    	for (register int i = 0; i < d; i ++) lnf0[i] = 1ll * lnf0[i] * inv % mod; for (register int i = d; i < len; i ++) lnf0[i] = 0;
    	for (register int i = d - 1; i > 0; i --) lnf0[i] = 1ll * lnf0[i - 1] * qpow (i, mod - 2) % mod; lnf0[0] = 0;
    }
    
    inline void Poly_Exp (register int d, register int * f, register int * f0) {
    	if (d == 1) return f0[0] = 1, void ();
    	Poly_Exp ((d + 1) >> 1, f, f0);
    	Poly_Ln (d, f0, lnf0);
    	register int len = 1, bit = 0;
    	while (len < (d << 1)) len <<= 1, bit ++;
    	for (register int i = 0; i < len; i ++) res[i] = 0, rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << bit - 1);
    	for (register int i = 0; i < d; i ++) res[i] = (f[i] - lnf0[i] + mod) % mod; res[0] ++;
    	NTT (len, f0, 3), NTT (len, res, 3);
    	for (register int i = 0; i < len; i ++) f0[i] = 1ll * f0[i] * res[i] % mod;
    	NTT (len, f0, inv3);
    	register int inv = qpow (len, mod - 2);
    	for (register int i = 0; i < d; i ++) f0[i] = 1ll * f0[i] * inv % mod; for (register int i = d; i < len; i ++) f0[i] = 0;
    }
    
    int main () {
    	n = read() - 1;
    	for (register int i = 0; i <= n; i ++) f[i] = read(); Poly_Exp (n + 1, f, f0);
    	for (register int i = 0; i <= n; i ++) printf ("%d ", f0[i]); putchar ('
    ');
    	return 0;
    }
    
  • 相关阅读:
    洛谷 P1464 Function【动态规划(递推)/记忆化搜索(递归)】
    洛谷 P1426 小鱼会有危险吗【模拟/题意理解】
    洛谷 P2089 烤鸡【DFS递归/10重枚举】
    洛谷 P1579 哥德巴赫猜想(升级版)【筛素数/技巧性枚举/易错】
    洛谷 P1618 三连击(升级版)【DFS/next_permutation()/技巧性枚举/sprintf】
    sprintf 心得
    洛谷 P1478 陶陶摘苹果(升级版)【贪心/结构体排序/可用01背包待补】
    吉首大学 问题 L: 小李子的老年生活
    AtCoder Beginner Contest 084 D
    一维差值维护心得
  • 原文地址:https://www.cnblogs.com/Rubyonly233/p/14212569.html
Copyright © 2020-2023  润新知