#6485. LJJ 学二项式定理
$$
\begin {aligned}
& \sum _ {i = 0} ^ n \binom n i s _ i a _ {i \bmod 4} \\
= & \sum _ {i = 0} ^ n \binom n i s _ i \sum _ {j = 0} ^ 3 a _ j [4 | i - j] \\
= & \sum _ {i = 0} ^ n \binom n i s _ i \sum _ {j = 0} ^ 3 a _ j \frac {\sum _ {k = 0} ^ 3 \omega _ 4 ^ {k(i - j)}} 4 \\
= & \frac {\sum _ {i = 0} ^ n \binom n i s _ i \sum _ {j = 0} ^ 3 a _ j \sum _ {k = 0} ^ 3 \omega _ 4 ^ {k(i - j)}} 4 \\
= & \frac {\sum _ {j = 0} ^ 3 a _ j \sum _ {k = 0} ^ 3 \omega _ 4 ^ {-kj} \sum _ {i = 0} ^ n \binom n i ({s \omega _ 4 ^ k}) ^ i } 4\\
= & \frac {\sum _ {j = 0} ^ 3 a _ j \sum _ {k = 0} ^ 3 \omega _ 4 ^ {-kj} ({s \omega _ 4 ^ k + 1} ^ n)} 4\\
\end {aligned}
$$
查看代码
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
| #include <cstdio> using namespace std; template <class Type> void read(Type &x) { char c; bool flag = false; while ((c = getchar()) < '0' || c > '9') c == '-' && (flag = true); x = c - '0'; while ((c = getchar()) >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - '0'; if (flag) x = ~x + 1; } template <class Type, class ...rest> void read(Type &x, rest &...y) { read(x), read(y...); } template <class Type> void write(Type x) { if (x < 0) putchar('-'), x = ~x + 1; if (x > 9) write(x / 10); putchar(x % 10 + '0'); } typedef long long LL; const int mod = 998244353; void adj (int &x) { x += x >> 31 & mod; } int binpow (int b, LL k = mod - 2) { int res = 1; for (; k; k >>= 1, b = (LL)b * b % mod) if (k & 1) res = (LL)res * b % mod; return res; } struct ModInt { int x; ModInt (int _ = 0) { adj(x = _); } int operator () () const { return x; } ModInt& operator += (const ModInt &_) { adj(x += _.x - mod); return *this; } ModInt& operator -= (const ModInt &_) { adj(x -= _.x); return *this; } ModInt& operator *= (const ModInt &_) { x = (LL)x * _.x % mod; return *this; } ModInt& operator /= (const ModInt &_) { x = (LL)x * binpow(_.x) % mod; return *this; } ModInt& operator ^= (const LL &_) { x = binpow(x, _); return *this; } ModInt operator + (const ModInt &_) const { ModInt res = x; res += _; return res; } ModInt operator - (const ModInt &_) const { ModInt res = x; res -= _; return res; } ModInt operator * (const ModInt &_) const { ModInt res = x; res *= _; return res; } ModInt operator / (const ModInt &_) const { ModInt res = x; res /= _; return res; } ModInt operator ^ (const LL &_) const { ModInt res = x; res ^= _; return res; } }; int main () { ModInt w(binpow(3, (mod - 1) / 4)); int T; read(T); for (LL n, s; T; --T) { read(n, s); ModInt res; for (int i = 0, a; i < 4; ++i) { read(a); ModInt t; for (int j = 0; j < 4; ++j) t += (((w ^ j) * s + 1) ^ n) / (w ^ (i * j)); res += t * a; } write((res / 4)()), puts(""); } return 0; }
|