当前位置:网站首页>[2022 national tournament simulation] BigBen -- determinant, Du Jiao sieve
[2022 national tournament simulation] BigBen -- determinant, Du Jiao sieve
2022-06-24 12:38:00 【Ouye xjx】
Good question ! Unfortunately, there is no link !
Title Description


Answer key
The calculation method is the same as the positive solution , But the Heisenberg matrix is not needed in the derivation process .
Consider replacing all diagonal elements with polynomials C + x C+x C+x, Then the determinant of this matrix becomes a polynomial , You can substitute x = 1 − C x=1-C x=1−C Find out the answer .
Combine the selected x x x You can get :
det ( A ) = ∑ S ⊂ { 1 , 2 , . . . , n } det ( B S ) x n − ∣ S ∣ \det(A)=\sum_{S\subset\{1,2,...,n\}}\det(B_S)x^{n-|S|} det(A)=S⊂{ 1,2,...,n}∑det(BS)xn−∣S∣ among B S B_S BS It's a A A A Replace the diagonal of with C C C Then limit it to S S S The matrix on this subset . such as :
Observe B S B_S BS You can find , If S S S The elements in can be divided by two ( That is, after sorting , Divide the previous by the next ), that B S B_S BS It's a lower triangular matrix , The determinant is C ∣ S ∣ C^{|S|} C∣S∣;
Otherwise, if you can't divide by two , Then there must be det ( B S ) = 0 \det(B_S)=0 det(BS)=0. This can be proved recursively :
If S S S There are two factors in which the number is not any other number , Then the lines of both numbers are all C C C, Then the matrix must not have the rank ;
conversely , S S S The largest number in must be a multiple of all numbers , Then the last row of the column is C C C, So you can delete the last row and column of the submatrix recursively . It is easy to find that the above rank is not satisfied in the end .
We make r = C 1 − C r=\frac{C}{1-C} r=1−CC, Then the problem is to find a set that satisfies the division of two elements S S S And :
A n s = ( 1 − C ) n ∑ S element plain two two whole except r ∣ S ∣ Ans=(1-C)^n\sum_{S Divide the elements by two }r^{|S|} Ans=(1−C)nS element plain two two whole except ∑r∣S∣
Make g x = ∑ max { i ∣ i ∈ S } = x r ∣ S ∣ g_x=\sum_{\max\{i|i\in S\}=x}r^{|S|} gx=∑max{ i∣i∈S}=xr∣S∣( Specially , g 1 g_1 g1 Express S = { 1 } S=\{1\} S={ 1} And empty sets ), Then you can enumerate the set without the maximum value , Get the transfer formula
g i = r ∑ j ∣ i g j g_i=r\sum_{j|i}g_j gi=rj∣i∑gj And initial value g 1 = r + 1 g_1=r+1 g1=r+1.
Our aim is to find g x g_x gx And , And this is just a formula that looks like a Dirichlet convolution and cannot be used to Min_25 sieve , Need to find another way .
Make s ( n ) = ∑ i = 1 n g i s(n)=\sum_{i=1}^ng_i s(n)=∑i=1ngi, We can actually enumerate directly S S S The state transition is obtained by the multiple relationship between the maximum value and the second maximum value in :
s ( n ) = 1 + r + ∑ i = 2 n s ( ⌊ n i ⌋ ) s(n)=1+r+\sum_{i=2}^ns(\lfloor\frac{n}{i}\rfloor) s(n)=1+r+i=2∑ns(⌊in⌋) So we get a direct radical divide and conquer enumeration .
However, the complexity of this approach is O ( n 3 4 ) O(n^{\frac{3}{4}}) O(n43), Can only pass 80 branch , Also optimize . Here we can follow the thought of Du Jiao sieve , Preprocess first g i g_i gi Before n 2 3 n^{\frac{2}{3}} n32 Find the prefix and the value , Then the rest of the radical divide and conquer enumeration , In this way, the complexity of radical divide and conquer can be reduced to O ( n 2 3 ) O(n^{\frac{2}{3}}) O(n32).
Now the problem is , Yes? O ( n ) O(n) O(n) Find out linearly g i g_i gi. consider x x x The only decomposition of , We find that if the number of times of all prime factors is the same , that g x g_x gx equal ( Because this is essentially a path count going to multiples , So all prime factors are equivalent ). We find the hash value of all elements by linear sieve , Then, if the hash values are equal, we only need to find them once .
The magic is , There are very few kinds of repeatable sets , Less than Line sex sieve Fan around \sqrt{ Linear sieve range } Line sex sieve Fan around , Therefore, we select the smallest number in the same hash value and directly enumerate the factors to find .
The final total complexity is O ( n 2 3 ) O(n^{\frac{2}{3}}) O(n32).
Code
#include<bits/stdc++.h>//JZM yyds!!
#define ll long long
#define lll __int128
#define uns unsigned
#define fi first
#define se second
#define IF (it->fi)
#define IS (it->se)
#define END putchar('\n')
#define lowbit(x) ((x)&-(x))
#define inline jzmyyds
using namespace std;
const int MAXN=2e6+5;
const ll INF=1e18;
ll read(){
ll x=0;bool f=1;char s=getchar();
while((s<'0'||s>'9')&&s>0){
if(s=='-')f^=1;s=getchar();}
while(s>='0'&&s<='9')x=(x<<1)+(x<<3)+(s^48),s=getchar();
return f?x:-x;
}
int ptf[50],lpt;
void print(ll x,char c='\n'){
if(x<0)putchar('-'),x=-x;
ptf[lpt=1]=x%10;
while(x>9)x/=10,ptf[++lpt]=x%10;
while(lpt>0)putchar(ptf[lpt--]^48);
if(c>0)putchar(c);
}
const ll MOD=998244353;
ll ksm(ll a,ll b,ll mo){
ll res=1;
for(;b;b>>=1,a=a*a%mo)if(b&1)res=res*a%mo;
return res;
}
unordered_map<ll,ll>mp;
mt19937 Rand(114514);
ll n,B,C,r,f[MAXN];
ll g[MAXN*10],mi[MAXN*10],hs[MAXN*10],ad[233];
bool nop[MAXN*10];
int pr[MAXN],le,m;
void sieve(int n){
nop[0]=nop[1]=1;
for(int a=2;a<=n;a++){
if(!nop[a])pr[++le]=a,mi[a]=1,hs[a]=ad[1];
for(int i=1,u;i<=le&&(u=pr[i]*a)<=n;i++){
nop[u]=1;
if(a%pr[i]==0){
mi[u]=mi[a]+1,hs[u]=hs[a]-ad[mi[a]]+ad[mi[u]];
break;
}mi[u]=1,hs[u]=hs[a]+ad[1];
}
}g[1]=(r+1)%MOD;
for(int x=2;x<=n;x++){
ll&re=mp[hs[x]];
if(!re){
re=g[1];
for(int i=2,lm=sqrt(x);i<=lm;i++)if(x%i==0){
re+=g[i];
if(x/i^i)re+=g[x/i];
}re=re%MOD*r%MOD;
}g[x]=re;
}
for(int i=2;i<=n;i++)(g[i]+=g[i-1])%=MOD;
}
int id(ll x){
return x<=B?x:B+n/x;}
int main()
{
freopen("bigben.in","r",stdin);
freopen("bigben.out","w",stdout);
n=read(),C=read(),B=sqrt(n),m=min(n,MAXN*10-50ll);
// double MUDA=clock();
if(!C)return print(1),0;
if(C==1)return print(n>2?0:1),0;
for(int i=1;i<=191;i++)ad[i]=Rand();
r=C*ksm(MOD+1-C,MOD-2,MOD)%MOD,f[id(1)]=(r+1)%MOD;
sieve(m);
for(ll d=2,x;d<=n;d=x+1){
if((x=n/(n/d))<=m){
f[id(x)]=g[x];continue;}
ll&res=f[id(x=n/(n/d))]=(r+1)%MOD;
for(ll i=2,j,la;i<=x;i=la+1)
j=x/i,la=x/j,(res+=(la-i+1)%MOD*r%MOD*f[id(j)])%=MOD;
}
print(f[id(n)]*ksm(MOD+1-C,n,MOD)%MOD);
// printf("%.0f\n",clock()-MUDA);
return 0;
}
边栏推荐
- 使用开源工具 k8tz 优雅设置 Kubernetes Pod 时区
- Getting started with scrapy
- GTEST from getting started to getting started
- How to apply for new bonds is it safe to open an account
- 巧妙构思-铁死亡调节因子分型预后发6+
- Kubernetes log viewer - kubetail
- [programming navigation] the practical code summarized by foreign great God, learned in 30 seconds!
- Cloud native database: the outlet of the database, you can also take off
- OpenGL es shared context for multi-threaded rendering
- Is it safe to apply for new bonds to open an account
猜你喜欢
Deep parsing and implementation of redis pub/sub publish subscribe mode message queue

GTEST from getting started to getting started
[mysql_16] variables, process control and cursors

MySQL 外键影响

Installation and operation of libuv

文本转语音功能上线,可以体验专业播音员的服务,诚邀试用

【2022国赛模拟】摆(bigben)——行列式、杜教筛

Ten thousand campus developers play AI in a fancy way. It's enough to see this picture!

使用开源工具 k8tz 优雅设置 Kubernetes Pod 时区

解析nc格式文件,GRB格式文件的依赖包edu.ucar.netcdfAll的api 学习
随机推荐
How to evaluate software development projects reasonably?
Continuous testing | making testing more free: practicing automated execution of use cases in coding
From theory to practice, decipher Alibaba's internal MySQL optimization scheme in simple terms
巧妙构思-铁死亡调节因子分型预后发6+
Remote terminal RTU slope monitoring and early warning
11+! 结肠癌中基于 m6A 调节因子的甲基化修饰模式以不同的肿瘤微环境免疫谱为特征
The world's largest meat processor has been "blackmailed", how many industries will blackmail virus poison?
Is GF Securities reliable? Is it safe to open a securities account?
Istio practical skills: implement header based authorization
105. 简易聊天室8:使用 Socket 传递图片
短信服务sms
LS-DYNA beginner's experience
Installing sqlserver extension PDO of PHP under Linux_ sqlsrv
The programmer's graduation project is still bald after a year
WPF从零到1教程详解,适合新手上路
It's settled! Bank retail credit risk control just does it!
Ghost, a synonym for blog system
Use go to process millions of requests per minute
Kubernetes practical skill: entering container netns
Coinbase will launch the first encrypted derivative product for retail traders