当前位置:网站首页>[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;
}
边栏推荐
- Fast and slow pointer series
- 华为路由器:GRE技术
- 1528. rearrange strings
- A tip to read on Medium for free
- K8s deployment of highly available PostgreSQL Cluster -- the road to building a dream
- 110. balanced binary tree recursive method
- Prompt code when MySQL inserts Chinese data due to character set problems: 1366
- 基于QingCloud的 “房地一体” 云解决方案
- Huawei Router: IPSec Technology
- 【LeetCode】415. 字符串相加
猜你喜欢
MBA-day25 最值问题-应用题
Spark - the number of leftouterjoin results is inconsistent with that of the left table
110. balanced binary tree recursive method
听说你还在花钱从网上买 PPT 模板?
Digital cloud released the 2022 white paper on digital operation of global consumers in the beauty industry: global growth solves marketing problems
From the Huawei weautomate digital robot forum, we can see the "new wisdom of government affairs" in the field of government and enterprises
2022-06-23: given a nonnegative array, select any number to make the maximum cumulative sum a multiple of 7, and return the maximum cumulative sum. N is larger, to the 5th power of 10. From meituan. 3
【E325: ATTENTION】vim编辑时报错
【量化投资】离散傅里叶变换求数组周期
every()、map()、forEarch()方法。数组里面有对象的情况
随机推荐
MySQL——SQL语句
解决:模型训练时loss出现nan
打印出来的对象是[object object],解决方法
GradScaler MaxClipGradScaler
Fast and slow pointer series
2022-06-23:给定一个非负数组,任意选择数字,使累加和最大且为7的倍数,返回最大累加和。 n比较大,10的5次方。 来自美团。3.26笔试。
SLAM14讲中Sophus包的安装问题
Wan Weiwei, a researcher from Osaka University, Japan, introduced the rapid integration method and application of robot based on WRS system
开源之夏中选名单已公示,基础软件领域成为今年的热门申请
linux(centos7.9)安装部署mysql-cluster 7.6
基于QingCloud的 “房地一体” 云解决方案
[team management] 25 tips for testing team performance management
Earthly container image construction tool -- the road to dream
从华为WeAutomate数字机器人论坛,看政企领域的“政务新智理”
216. combined summation III enumeration method
Qingcloud based R & D cloud solution for geographic information enterprises
Data midrange: analysis of full stack technical architecture of data midrange, with industry solutions
520. 检测大写字母
YOLOX backbone——CSPDarknet的实现
Data middle office: middle office practice and summary