当前位置:网站首页>[LOJ 6485] LJJ binomial theorem (unit root inversion) (template)
[LOJ 6485] LJJ binomial theorem (unit root inversion) (template)
2022-07-29 08:45:00 【SSL_ TJH】
LJJ Learn binomial theorem
Topic link :LOJ 6485
The main idea of the topic
Find an equation :
∑ i = 0 n ( ( n i ) s i a i m o d 4 ) \sum\limits_{i=0}^n(\binom{n}{i}s^ia_{i\bmod 4}) i=0∑n((in)siaimod4)
among n ≤ 1 0 18 n\leq 10^{18} n≤1018
Ideas
This problem can be regarded as the template problem of unit root inversion .
Unit root inversion
First, the unit root inversion is used to deal with the formula with modulus .
( There is a module in the coefficient that can be removed with this )
Then the formula is [ n ∣ a ] = 1 n ∑ k = 0 n − 1 ω n a k [n|a]=\dfrac{1}{n}\sum\limits_{k=0}^{n-1}\omega_n^{ak} [n∣a]=n1k=0∑n−1ωnak
Then prove it :
if a ≠ 0 ( m o d n ) a\neq 0(\bmod\ n) a=0(mod n)
Then we can sum it with an equal ratio sequence :
1 n ω n a n − 1 ω n a − 1 \dfrac{1}{n}\dfrac{\omega_n^{an}-1}{\omega_n^a-1} n1ωna−1ωnan−1
then ω n a ≠ 1 , ω n a − 1 ≠ 0 \omega^a_n\neq 1,\omega_n^a-1\neq 0 ωna=1,ωna−1=0 Denominator is ok , Molecular cause ω n n = ω n 0 = 1 \omega_n^n=\omega_n^0=1 ωnn=ωn0=1, ω n a n = ( ω n n ) a = 1 , ω n a n − 1 = 0 \omega^{an}_n=(\omega_n^n)^a=1,\omega_n^{an}-1=0 ωnan=(ωnn)a=1,ωnan−1=0
if a = 0 ( m o d n ) a=0(\bmod\ n) a=0(mod n)
That special treatment ( Because at this time, there is 0 0 0)
1 n ∑ k = 0 n − 1 ω n a k m o d n \dfrac{1}{n}\sum\limits_{k=0}^{n-1}\omega_n^{ak\bmod n} n1k=0∑n−1ωnakmodn
1 n ∑ k = 0 n − 1 ω n 0 = 1 n n = 1 \dfrac{1}{n}\sum\limits_{k=0}^{n-1}\omega_n^{0}=\dfrac{1}{n}n=1 n1k=0∑n−1ωn0=n1n=1
Then a classic formula :
[ a = b ( m o d n ) ] = [ a − b = 0 ( m o d n ) ] = [ n ∣ ( a − b ) ] [a=b\pmod n]=[a-b=0\pmod n]=[n|(a-b)] [a=b(modn)]=[a−b=0(modn)]=[n∣(a−b)]
= 1 n ∑ k = 0 n − 1 ω n ( a − b ) k = 1 n ∑ k = 0 n − 1 ω n a k ω n − b k =\dfrac{1}{n}\sum\limits_{k=0}^{n-1}\omega_n^{(a-b)k}=\dfrac{1}{n}\sum\limits_{k=0}^{n-1}\omega_n^{ak}\omega_n^{-bk} =n1k=0∑n−1ωn(a−b)k=n1k=0∑n−1ωnakωn−bk
This question
∑ i = 0 n ( ( n i ) s i a i m o d 4 ) \sum\limits_{i=0}^n(\binom{n}{i}s^ia_{i\bmod 4}) i=0∑n((in)siaimod4)
∑ i = 0 n ( ( n i ) s i ( ∑ j = 0 3 a j [ i m o d 4 = j ] ) ) \sum\limits_{i=0}^n(\binom{n}{i}s^i(\sum\limits_{j=0}^3a_j[i\bmod 4=j])) i=0∑n((in)si(j=0∑3aj[imod4=j]))
∑ i = 0 n ( ( n i ) s i ( ∑ j = 0 3 a j [ 4 ∣ i − j ] ) ) \sum\limits_{i=0}^n(\binom{n}{i}s^i(\sum\limits_{j=0}^3a_j[4|i-j])) i=0∑n((in)si(j=0∑3aj[4∣i−j]))
∑ i = 0 n ( ( n i ) s i ( ∑ j = 0 3 a j ( 1 4 ∑ k = 0 3 ω 4 i k ω 4 − j k ) ) ) \sum\limits_{i=0}^n(\binom{n}{i}s^i(\sum\limits_{j=0}^3a_j(\dfrac{1}{4}\sum\limits_{k=0}^{3}\omega_4^{ik}\omega_4^{-jk}))) i=0∑n((in)si(j=0∑3aj(41k=0∑3ω4ikω4−jk)))
1 4 ∑ k = 0 3 ( ∑ j = 0 3 a j ω 4 − j k ) ( ∑ i = 0 n ( n i ) s i ω 4 i k ) \dfrac{1}{4}\sum\limits_{k=0}^{3}(\sum\limits_{j=0}^3a_j\omega_4^{-jk})(\sum\limits_{i=0}^n\binom{n}{i}s^i\omega_4^{ik}) 41k=0∑3(j=0∑3ajω4−jk)(i=0∑n(in)siω4ik)
( binomial theorem )
∑ i = 0 n ( n i ) s i ω 4 i k \sum\limits_{i=0}^n\binom{n}{i}s^i\omega_4^{ik} i=0∑n(in)siω4ik
∑ i = 0 n ( n i ) ( s ω 4 k ) i 1 n − i \sum\limits_{i=0}^n\binom{n}{i}(s\omega_4^{k})^i1^{n-i} i=0∑n(in)(sω4k)i1n−i
( s ω 4 k + 1 ) n (s\omega_4^k+1)^n (sω4k+1)n
( Back to the original )
1 4 ∑ k = 0 3 ( ∑ j = 0 3 a j ω 4 − j k ) ( s ω 4 k + 1 ) n \dfrac{1}{4}\sum\limits_{k=0}^{3}(\sum\limits_{j=0}^3a_j\omega_4^{-jk})(s\omega_4^k+1)^n 41k=0∑3(j=0∑3ajω4−jk)(sω4k+1)n
then ω 4 1 = g ( m o d − 1 ) / 4 \omega_4^1=g^{(mod-1)/4} ω41=g(mod−1)/4.
Code
#include<cstdio>
#define ll long long
#define mo 998244353
using namespace std;
ll n, s, a[4], G = 3, Gv, v4, ans, w[4];
ll ksm(ll x, ll y) {
ll re = 1; while (y) {
if (y & 1) re = re * x % mo; x = x * x % mo; y >>= 1;} return re;}
int main() {
int T; scanf("%d", &T); Gv = ksm(G, mo - 2); v4 = ksm(4, mo - 2);
w[0] = 1; w[1] = ksm(G, (mo - 1) / 4); for (int i = 2; i < 4; i++) w[i] = w[i - 1] * w[1] % mo;
while (T--) {
scanf("%lld %lld", &n, &s); for (int i = 0; i < 4; i++) scanf("%lld", &a[i]);
ans = 0;
for (int k = 0; k <= 3; k++) {
ll now = 0;
for (int j = 0; j <= 3; j++)
(now += a[j] * w[(4 - j) * k % 4] % mo) %= mo;
(ans += now * ksm((s * w[k] % mo + 1) % mo, n) % mo) %= mo;
}
printf("%lld\n", ans * v4 % mo);
}
return 0;
}
边栏推荐
- Simple operation of SQL server data table
- Group Backpack
- PostgreSQL manually creates hikaridatasource to solve the error cannot commit when autocommit is enabled
- 预训练模型与传统方法在排序上有啥不同?
- Source code compilation pytorch pit
- Day6: use PHP to write file upload page
- Lesson 3 threejs panoramic preview room case
- 6.2 function-parameters
- 7.3-function-templates
- Basic shell operations (Part 2)
猜你喜欢
2022 P cylinder filling test simulation 100 questions simulation test platform operation
Qpalette learning notes
Basic shell operations (Part 2)
Clion+opencv+aruco+cmake configuration
Week 1 task deep learning and pytorch Foundation
Clickhouse learning (II) Clickhouse stand-alone installation
(视频+图文)机器学习入门系列-第3章 逻辑回归
C language function output I love you
Day5: PHP simple syntax and usage
Sword finger offer 50. the first character that appears only once
随机推荐
Node: file write data (readfile, WriteFile), two modes: overwrite and increment
[opencv] - Operator (Sobel, canny, Laplacian) learning
Personal study notes
2022.7.9 quick view of papers
数学建模——微分方程
2022电工(初级)考题模拟考试平台操作
Lesson 3 threejs panoramic preview room case
What if official account does not support markdown format file preparation?
Chrony 时间同步
Arfoundation Getting Started tutorial 7-url dynamically loading image tracking Library
信息系统项目管理师必背核心考点(五十三)质量等级
Ga-rpn: recommended area network for guiding anchors
Osgsimplegl3 combined with renderdoc tool
Day15 (day16 extension): file contains vulnerability
Osgsimplegl3 example analysis
English high frequency suffix
PostgreSQL manually creates hikaridatasource to solve the error cannot commit when autocommit is enabled
Group Backpack
MFC integration QT verification and problem handling
Third week weekly report resnet+resnext