• 拉格朗日反演


    1.幂级数的复合

    对于幂级数(F(x))(G(x)),我们称(F(G(x)))为幂级数F和G的复合

    2.复合逆:

    如果(F(x))(G(x))满足(F(G(x))=G(F(x))=x)则称它们互为复合逆

    3.拉格朗日反演:

    如果(F(x))(G(x))互为复合逆,则有([x^n]G(x)=frac1n[x^{n-1}](frac{1}{F(x)/x})^n)

    可以通过这个在(O(nlog n))(多项式exp和ln求快速幂,巨大常数)或(O(nlog^2n))(倍增快速幂,小常数)来求复合逆的某一项(如果求整个复合逆的最优复杂度为(O(n^2))的大步小步思想)

    一下为多项式倍增快速幂取模和拉格朗日反演的板子,可以配合ghj1222的多项式板子食用

    void poly_qpow(int *a, int len, int n)
    {
    	int *tmp = new int[len * 2];
    	for (int i = 0; i < len * 2; i++) tmp[i] = i >= len ? 0 : a[i], a[i] = (i == 0);
    	while (n > 0)
    	{
    		ntt(tmp, len * 2, 1);
    		if (n & 1)
    		{
    			ntt(a, len * 2, 1);
    			for (int i = 0; i < len * 2; i++) a[i] = a[i] * (long long)tmp[i] % p;
    			ntt(a, len * 2, -1);
    			for (int i = len; i < len * 2; i++) a[i] = 0;
    		}
    		for (int i = 0; i < len * 2; i++) tmp[i] = tmp[i] * (long long)tmp[i] % p;
    		ntt(tmp, len * 2, -1);
    		for (int i = len; i < len * 2; i++) tmp[i] = 0;
    		n >>= 1;
    	}
    	delete []tmp;
    }
    
    int lagrange_inversion(int *aa, int len, int n)
    {
    	int *a = new int[len * 2];
    	for (int i = 0; i < len; i++) a[i] = aa[i];
    	for (int i = len; i < len * 2; i++) a[i] = 0;
    	for (int i = 1; i < len; i++) a[i - 1] = a[i];
    	poly_inv(a, len);
    	poly_qpow(a, len, n);
    	int ans = a[n - 1] * (long long)qpow(n, p - 2) % p;
    	delete []a;
    	return ans;
    }
    
  • 相关阅读:
    ios开发常用工具集合网站
    xib自定义UIView报错误 "forUndefinedKey:]: this class is not key value coding-compliant for the key"
    IOS MJExtension json转模型的轻量级框架的使用(转载)
    升级Xcode之后VVDocumenter-Xcode不能用的解决办法
    iOS开发系列--并行开发其实很容易
    通讯录开发
    UIGestureRecognizer手势
    UIScrollView
    UIStepper
    UIPickerView
  • 原文地址:https://www.cnblogs.com/oier/p/10400448.html
Copyright © 2020-2023  润新知