zoukankan      html  css  js  c++  java
  • Solution -「LOJ #6485」 LJJ 学二项式定理

    (mathcal{Description})

      Link.

      给定 (n,s,a_0,a_1,a_2,a_3),求:

    [sum_{i=0}^ninom{n}is^ia_{imod4}mod998244353 ]

      多测,数据组数 (le10^5)(nle10^{18}),其余输入 (le10^8)

    (mathcal{Solution})

      单位根反演板题。记一个函数 (f) 有:

    [egin{aligned} f(x)&=sum_{i=0}^ninom{n}is^ix^i\ &=(sx+1)^n end{aligned} ]

      问题即求 (imod4=0,1,2,3)(a_i)([x^i]f(x)) 之和。以 (imod4=0) 为例:

    [egin{aligned} sum_{i=0}^n[4|i]a_0[x^i]f(x)&=frac{1}4a_0sum_{i=0}^nleft(sum_{j=0}^3omega_4^{ij} ight)inom{n}is^i\ &=frac{1}4a_0sum_{j=0}^3f(omega_4^j) end{aligned} ]

      直接代四个单位根进去算出来即可。对于其他三个 (imod4) 的值,将 (f) 的各系数位移就能类似地求出答案。

      复杂度 (mathcal O(Tlog n))( imes4^2) 的常数)。

    (mathcal{Code})

    /* Clearink */
    
    #include <cstdio>
    
    #define rep( i, l, r ) for ( int i = l, repEnd##i = r; i <= repEnd##i; ++i )
    #define per( i, r, l ) for ( int i = r, repEnd##i = l; i >= repEnd##i; --i )
    
    typedef long long LL;
    
    inline LL rint () {
    	LL x = 0, f = 1; char s = getchar ();
    	for ( ; s < '0' || '9' < s; s = getchar () ) f = s == '-' ? -f : f;
    	for ( ; '0' <= s && s <= '9'; s = getchar () ) x = x * 10 + ( s ^ '0' );
    	return x * f;
    }
    
    template<typename Tp>
    inline void wint ( Tp x ) {
    	if ( x < 0 ) putchar ( '-' ), x = -x;
    	if ( 9 < x ) wint ( x / 10 );
    	putchar ( x % 10 ^ '0' );
    }
    
    const int MOD = 998244353, G = 3, INV4 = 748683265;
    LL n;
    int w[4], s, a[4];
    
    inline int mul ( const long long a, const int b ) { return a * b % MOD; }
    inline int add ( int a, const int b ) { return ( a += b ) < MOD ? a : a - MOD; }
    inline int mpow ( int a, int b ) {
    	int ret = 1;
    	for ( ; b; a = mul ( a, a ), b >>= 1 ) ret = mul ( ret, b & 1 ? a : 1 );
    	return ret;
    }
    
    inline int f ( const int x ) {
    	return mpow ( add ( mul ( s, x ), 1 ), n );
    }
    
    int main () {
    	w[0] = 1, w[1] = mpow ( G, MOD - 1 >> 2 );
    	w[2] = mul ( w[1], w[1] ), w[3] = mul ( w[2], w[1] );
    	for ( int T = rint (); T--; ) {
    		n = rint () % ( MOD - 1 ), s = rint ();
    		rep ( i, 0, 3 ) a[i] = rint ();
    		int ans = 0;
    		rep ( r, 0, 3 ) {
    			int res = 0;
    			rep ( i, 0, 3 ) {
    				res = add ( res,
    					mul ( f ( w[i] ), mpow ( w[r * i & 3], MOD - 2 ) ) );
    			}
    			ans = add ( ans, mul ( res, a[r] ) );
    		}
    		wint ( mul ( ans, INV4 ) ), putchar ( '
    ' );
    	}
    	return 0;
    }
    
  • 相关阅读:
    MySQL多表查询
    多表关联
    MySQL数据类型 约束
    初识数据库
    socker server和 event
    os 模块 和 os模块下的path模块
    sys 模块
    time 模块
    目录规范

  • 原文地址:https://www.cnblogs.com/rainybunny/p/14237899.html
Copyright © 2011-2022 走看看