当前位置:网站首页>[noi simulation] pendulum (linear algebra, Du Jiao sieve)
[noi simulation] pendulum (linear algebra, Du Jiao sieve)
2022-06-24 08:59:00 【DD(XYX)】
Topic
6s , 1024mb
I am a XYX, I'm good at swinging .
I saw one when I was putting it on n × n n\times n n×n Matrix A A A :
A i , j = { 1 i = j 0 i ≠ j ∧ i ∣ j C o t h e r w i s e A_{i,j}=\begin{cases} 1 & i=j\\ 0 & i\not=j\land i|j\\ C & {\rm otherwise} \end{cases} Ai,j=⎩⎪⎨⎪⎧10Ci=ji=j∧i∣jotherwise
Now I want to know A A A The determinant of , Because I put , So the answer just needs to be right 998244353 998244353 998244353 modulus .
1 ≤ n ≤ 1 0 11 , 0 ≤ C < 998244353 1\leq n\leq10^{11},0\leq C<998244353 1≤n≤1011,0≤C<998244353 .
Examples :
6 2 → \rightarrow →998244350
99 4 → \rightarrow →714389845
10000000000 10 → \rightarrow →82177551
Answer key
This problem tells us , It is not necessary to construct upper triangular or lower triangular matrix to calculate determinant .
We can also construct Heisenberg matrix relatively easily .
This is the matrix A A A :
[ 1 0 0 0 0 … C 1 C 0 C … C C 1 C C … C C C 1 C … C C C C 1 … … … … … … ⋱ ] \left[\begin{matrix} 1 & 0 & 0 & 0 &0&\ldots\\ C & 1 & C & 0 & C&\ldots\\ C & C & 1 & C & C&\ldots\\ C & C & C & 1 & C&\ldots\\ C & C & C & C & 1 &\ldots\\ \ldots&\ldots&\ldots&\ldots&\ldots&\ddots \end{matrix}\right] ⎣⎢⎢⎢⎢⎢⎢⎡1CCCC…01CCC…0C1CC…00C1C…0CCC1………………⋱⎦⎥⎥⎥⎥⎥⎥⎤
Let's put the matrix A A A Subtract the upper line from each line ( Start from below , Subtract the previous line from each line , The first line doesn't move ), We can get a Shanghai senberg matrix :
[ 1 0 0 0 0 … C − 1 1 C 0 C … 0 C − 1 1 − C C 0 … 0 0 C − 1 1 − C 0 … 0 0 0 C − 1 1 − C … … … … … … ⋱ ] \left[\begin{matrix} 1 & 0 & 0 & 0 &0&\ldots\\ C-1 & 1 & C & 0 & C&\ldots\\ 0 & C-1 & 1-C & C & 0&\ldots\\ 0 & 0 & C-1 & 1-C & 0&\ldots\\ 0 & 0 & 0 & C-1 & 1-C &\ldots\\ \ldots&\ldots&\ldots&\ldots&\ldots&\ddots \end{matrix}\right] ⎣⎢⎢⎢⎢⎢⎢⎡1C−1000…01C−100…0C1−CC−10…00C1−CC−1…0C001−C………………⋱⎦⎥⎥⎥⎥⎥⎥⎤
Each permutation ring of the matrix is a counter clockwise ring with continuous labels , Be similar to i → j → j − 1 → . . . → i + 1 i\rightarrow j\rightarrow j-1 \rightarrow...\rightarrow i+1 i→j→j−1→...→i+1 Of . Differential obtainable , Each multiple relationship in the upper right i ∣ j i|j i∣j , Will give A i , j A_{i,j} Ai,j contribution − C -C −C , to A i + 1 , j A_{i+1,j} Ai+1,j contribution C C C. We multiply each position of the matrix by 1 1 − C \frac{1}{1-C} 1−C1 , Then make f i f_i fi Before retention i i i That's ok i i i Determinant of column , that
f i = f i − 1 + C 1 − C ∑ j ∣ i , j < i ( f j − f j − 1 ) f_i=f_{i-1}+\frac{C}{1-C}\sum_{j|i,j<i} (f_j-f_{j-1}) fi=fi−1+1−CCj∣i,j<i∑(fj−fj−1)
set up g i = f i − f i − 1 g_i=f_i-f_{i-1} gi=fi−fi−1 , that g i = C 1 − C ∑ j ∣ i , j < i g j g_i=\frac{C}{1-C}\sum_{j|i,j<i}g_j gi=1−CC∑j∣i,j<igj .
So what we want is g i g_i gi And f n f_n fn , The data range should be a sub linear sieve .
Make h 1 = − 1 , h i = C 1 − C h_1=-1,h_{i}=\frac{C}{1-C} h1=−1,hi=1−CC , that ( Dirichlet convolution ) h ∗ g = − e h*g=-e h∗g=−e , So you can Dujiao sieve ( Duchenne sieve is not restricted to be a product function ).
∑ i = 1 n ∑ j ∣ i h j g i / j = ∑ j n h j ∑ i n / j g i = − 1 ⇒ f n = 1 + ∑ j = 2 n h j f n / j \sum_{i=1}^{n}\sum_{j|i}h_jg_{i/j}=\sum_{j}^nh_j\sum_{i}^{n/j}g_i=-1\\ \Rightarrow f_n=1+\sum_{j=2}^nh_jf_{n/j} i=1∑nj∣i∑hjgi/j=j∑nhji∑n/jgi=−1⇒fn=1+j=2∑nhjfn/j
We preprocess n 2 / 3 n^{2/3} n2/3 Inside f i f_i fi , So the complexity of Du Jiao sieve is O ( n 2 / 3 ) O(n^{2/3}) O(n2/3) .
But preprocessing can easily bring a log \log log , So we need to optimize .
Make x = ∏ p i w i x=\prod p_i^{w_i} x=∏piwi , We put p i p_i pi Change from small to large 2 , 3 , 5 , 7 , . . . 2,3,5,7,... 2,3,5,7,... obtain y = ∏ p ′ i w i y=\prod p{'}_i^{w_i} y=∏p′iwi , Easy to find g x = g y g_x=g_y gx=gy , because g g g Only follow w i w_i wi On the resettable set of . We use Euler sieve to find the maximum prime factor and the number of prime factors for each number , And then recursively calculate each x x x Corresponding y y y . Violence finds something fundamentally different y y y Only a thousand at most , We can each O ( n 1 / 3 ) O(n^{1/3}) O(n1/3) Find out g g g .
Be careful , Because every position of the matrix is multiplied by 1 1 − C \frac{1}{1-C} 1−C1 , And because the upper left corner of the matrix is not standard , So the final answer is
f n ⋅ ( 1 − C ) n − 1 f_n\cdot (1-C)^{n-1} fn⋅(1−C)n−1
The sum O ( n 2 / 3 ) O(n^{2/3}) O(n2/3) .
CODE
#include<map>
#include<set>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<random>
#include<bitset>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#pragma GCC optimize(2)
using namespace std;
#define MAXN 10000005
#define LL long long
#define ULL unsigned long long
#define ENDL putchar('\n')
#define DB double
#define lowbit(x) (-(x) & (x))
#define FI first
#define SE second
#define PR pair<int,int>
int xchar() {
static const int maxn = 1000000;
static char b[maxn];
static int pos = 0,len = 0;
if(pos == len) pos = 0,len = fread(b,1,maxn,stdin);
if(pos == len) return -1;
return b[pos ++];
}
// #define getchar() xchar()
LL read() {
LL f = 1,x = 0;int s = getchar();
while(s < '0' || s > '9') {
if(s<0)return -1;if(s=='-')f=-f;s = getchar();}
while(s >= '0' && s <= '9') {
x = (x<<1) + (x<<3) + (s^48);s = getchar();}
return f*x;
}
void putpos(LL x) {
if(!x)return ;putpos(x/10);putchar((x%10)^48);}
void putnum(LL x) {
if(!x) {
putchar('0');return ;}
if(x<0) putchar('-'),x = -x;
return putpos(x);
}
void AIput(LL x,int c) {
putnum(x);putchar(c);}
const int MOD = 998244353;
int n,m,s,o,k;
LL N;
inline int qkpow(int a,int b) {
int res = 1;
while(b > 0) {
if(b & 1) res = res *1ll* a % MOD;
a = a *1ll* a % MOD; b >>= 1;
} return res;
}
int V;
int sg[MAXN],lw[MAXN],ct[MAXN],hb[MAXN];
int p[MAXN],cnt; bool f[MAXN];
void sieve(int n) {
sg[1] = 1; lw[1] = 1; int nm = 0;
for(int i = 2;i <= n;i ++) {
if(!f[i]) p[++ cnt] = i,lw[i] = 2,hb[i] = i,ct[i] = 1;
if(lw[i] == i) {
for(int j = 1;j * j <= i;j ++) {
if(i % j == 0) {
(sg[i] += sg[j]) %= MOD;
if(i/j > j && j > 1) {
(sg[i] += sg[i/j]) %= MOD;
}
}
}
sg[i] = sg[i] *1ll* V % MOD;
}
else sg[i] = sg[lw[i]];
for(int j = 1;j <= cnt && (nm=i*p[j]) <= n;j ++) {
f[nm] = 1; hb[nm] = hb[i];
if(i % p[j] == 0) {
ct[nm] = ct[i];
lw[nm] = lw[nm/hb[nm]] * p[ct[nm]];
break;
}
ct[nm] = ct[i] + 1;
lw[nm] = lw[nm/hb[nm]] * p[ct[nm]];
}
}
for(int i = 2;i <= n;i ++) {
(sg[i] += sg[i-1]) %= MOD;
}
return ;
}
int sh(LL x) {
if(x<1) return 0;
return ((x-1)%MOD*V%MOD +MOD-1) % MOD;
}
int s1[1000005];
int Sg(LL x) {
if(x <= 10000000) return sg[x];
int &rs = s1[N/x];
if(rs >= 0) return rs;
rs = 1;
for(LL i = 2;i <= x;i ++) {
LL r = x/(x/i);
rs += (r-i+1)%MOD*V%MOD *1ll* Sg(x/i) % MOD;
if(rs >= MOD) rs -= MOD;
i = r;
} return rs;
}
int main() {
freopen("bigben.in","r",stdin);
freopen("bigben.out","w",stdout);
N = read(); int C = read();
if(C <= 1) return AIput(N<=2,'\n'),0;
V = C *1ll* qkpow(MOD+1-C,MOD-2) % MOD;
sieve(10000000);
memset(s1,-1,sizeof(s1));
int as = Sg(N) *1ll* qkpow(MOD+1-C,(N-1)%(MOD-1)) % MOD;
AIput(as,'\n');
return 0;
}
边栏推荐
- 疫情、失业,2022,我们高喊着摆烂和躺平!
- Array opposite pointer series
- A tip to read on Medium for free
- Deep learning and neural networks: the six most noteworthy trends
- What is the future development trend of Business Intelligence BI
- MySQL | 视图《康师傅MySQL从入门到高级》笔记
- Analyze the meaning of Internet advertising terms CPM, CPC, CPA, CPS, CPL and CPR
- [quantitative investment] discrete Fourier transform to calculate array period
- Database to query the quantity of books lent in this month. If it is higher than 10, it will display "more than 10 books lent in this month". Otherwise, it will display "less than 10 books lent in thi
- 数据中台:民生银行的数据中台实践方案
猜你喜欢

KaFormer个人笔记整理

110. 平衡二叉树-递归法

4274. suffix expression

every()、map()、forEarch()方法。数组里面有对象的情况

How to configure environment variables and distinguish environment packaging for multi terminal project of uniapp development

【LeetCode】387. 字符串中的第一个唯一字符

Opencv maximum filtering (not limited to images)

数据中台:数据中台技术架构详解

【LeetCode】415. 字符串相加
![[e325: attention] VIM editing error](/img/58/1207dec27b3df7dde19d03e9195a53.png)
[e325: attention] VIM editing error
随机推荐
从华为WeAutomate数字机器人论坛,看政企领域的“政务新智理”
Huawei Router: GRE Technology
IDEA另起一行快捷键
Data midrange: detailed explanation of the technical stack of data acquisition and extraction
2021-05-20computed和watch应用与区别
基于QingCloud的地理信息企业研发云解决方案
"I can't understand Sudoku, so I choose to play Sudoku."
The list of open source summer winners has been publicized, and the field of basic software has become a hot application this year
Floating error waiting for changelog lock
SLAM14讲中Sophus包的安装问题
数云发布2022美妆行业全域消费者数字化经营白皮书:全域增长破解营销难题
Jenkins is deployed automatically and cannot connect to the dependent service [solved]
KaFormer个人笔记整理
所说的Get post:请求的区别,你真的知道了吗??????
OpenCV每日函数 结构分析和形状描述符(7) 寻找多边形(轮廓)/旋转矩形交集
Array opposite pointer series
JS to find and update the specified value in the object through the key
A tip to read on Medium for free
Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system
【NOI模拟赛】摆(线性代数,杜教筛)