Special test mathematics 1

Posted by brissy_matty on Tue, 04 Jan 2022 21:24:48 +0100

A. young

The weight of the minimum spanning tree under expectation

Due to XOR, binary splitting is considered, and the contribution of each bit is considered separately

In the current bit, you must put the bits that are \ (1 \) and \ (0 \) together, and then connect the two pieces with \ (1 \) edges to connect them

Then let \ (f {n, m} \) represent the minimum spanning tree sum in all cases with a total of \ (n \) points with weights ranging from \ (0 \) to \ (2^m-1 \)

According to the above, the contribution can be divided into two parts

1. Connecting edge in block

2. Connecting edge between blocks

The first part can be solved recursively. The second part needs to make another \ (dp \). Let \ (g {s, t, m} \) represent \ (s \) points on one side and \ (t \) points on the other side. The weight range is the minimum sum of edge weights between both sides in all cases from \ (0 \) to \ (2^m-1 \)

Then we can enumerate the sizes on both sides and get the expression \ (dp \), where the size on one side is \ (s \) and the size on the other side is \ (n-s \) set to \ (t \)

\(f_{n,m}= \sum\limits_{s=0}^n\binom{n}{s}(2^{(m-1)\times t}\times f_{s,m-1}+2^{(m-1)\times s}\times f_{t,m-1}+g_{s,t,m-1}+[t\neq 0 \& s\neq 0]2^{(m-1)\times (n+1)})\)

Explain that \ (\ binom{n}{s} \) needs to select \ (s \) points to form the one with \ (1 \) or \ (0 \). The meaning of \ (t \) is opposite

\(2^{(m-1)\times t}\times f_{s,m-1} \) has a total of \ (2 ^ {(m-1)} \) values. You can select another set with a total of \ (t \) values. The values of the two sets do not affect each other, so you can directly multiply the number of cases above, and the latter one is the same

\(g) same as definition

\([t \ NEQ 0 \ & s \ NEQ 0] 2 ^ {(m-1) \ times (n + 1)} \) when both sets exist, the middle edge must produce \ (2^{m-1} \) contribution, multiplied by the number of randomly selected schemes at all points

Let's look at how to find \ (g \) directly, so it can be transformed into finding \ (s \) points on one side and \ (t \) points on the other side. The weight range is \ (0 \) to \ (2^m-1 \). The edge weight of the minimum side is greater than or equal to the number of schemes of \ (k \), and set this as \ (p_{s,t,m,k} \)

Then \ (g {s, t, m} = \ sum \ limits {k = 1} ^ {2 ^ M-1} P {s, t, m, K} \)

Perceptually understand the transformation. When the minimum edge weight is \ (k \), the same scheme will be calculated once from greater than or equal to \ (1 \) to greater than or equal to \ (k \), just producing the contribution of \ (k \)

Let's see how to find \ (p \)

According to the value of bit \ (m \), divide \ (s,t \) into \ (s0,s1,t0,t1 \) respectively, and then recursively solve it

If the \ (m \) bit of \ (k \) is \ (1 \), only \ (s1,t0 \) and \ (s0,t1 \) can exist at the same time and recurse directly to the next layer

If the \ (m \) bit of \ (k \) is \ (0 \) and if \ (s0,t0 \) and \ (s1,t1 \) exist at the same time, the contribution of this bit can only be \ (0 \)

It needs to be solved recursively, and of course, the coefficient multiplied by the combination number

If the two situations do not exist at the same time, this one's contribution must have a contribution, plus the number of randomly selected schemes

\(p \) when the boundary is \ (m=0 \) \ (k=0 \) contributes a scheme, while the set on one side is empty and contributes \ (2^{s\times m} \) schemes, which should be understood in combination with the code

\Contribution \ (0 \) when the boundary of (g \) is \ (m=0 \) or \ (s=0 \)

\Contribution \ (0 \) when the boundary of (f \) \ (m=0 \) or \ (n\leq1 \)

Code
#include<bits/stdc++.h>
#define int long long
#define rint signed
#define mod 258280327
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
int n,m;
int C[60][60],k2[1010];
unordered_map<int,int>f[60],g[60][60],p[60][60][10];
inline int qpow(int x,int k){
	int res=1,base=x;
	while(k){if(k&1) res=res*base%mod;base=base*base%mod;k>>=1;}
	return res;
}
int P(int s,int t,int m,int k){
	if(s>t) swap(s,t);if(!m) return k==0;if(!s) return k2[t*m];
	if(p[s][t][m].find(k)!=p[s][t][m].end()) return p[s][t][m][k];
	if(k&(1<<(m-1))) return p[s][t][m][k]=P(s,t,m-1,k^(1<<(m-1)))*2%mod;
	int res=0;
	for(int s0=0,s1;s0<=s;s0++) for(int t0=0,t1;t0<=t;t0++){
		s1=s-s0,t1=t-t0;
		if((s1&&t1)||(s0&&t0)) res=(res+C[s][s0]*C[t][t0]%mod*P(s0,t0,m-1,k)%mod*P(s1,t1,m-1,k)%mod)%mod;
	}
	return p[s][t][m][k]=(res+k2[(s+t)*(m-1)+1])%mod;
}
inline int G(int s,int t,int m){
	if(s>t) swap(s,t);if(!m||!s) return 0;
	if(g[s][t].find(m)!=g[s][t].end()) return g[s][t][m];
	int res=0,U=(1<<m)-1;
	for(int k=1;k<=U;k++) res=(res+P(s,t,m,k))%mod;
	return g[s][t][m]=res;
}
inline int F(int n,int m){
	if(!m||n<=1) return 0;
	if(f[n].find(m)!=f[n].end()) return f[n][m];
	int res=0;
	for(int s=0,t;s<=n;s++){
		t=n-s;
		res=(res+C[n][s]*(k2[(m-1)*t]*F(s,m-1)%mod+k2[(m-1)*s]*F(t,m-1)%mod+G(s,t,m-1)+(s!=0&&t!=0)*k2[(m-1)*(n+1)])%mod)%mod;
	}
	return f[n][m]=res;
}
signed main(){
#ifdef LOCAL
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
	n=read(),m=read();k2[0]=1;for(int i=1;i<=1000;i++) k2[i]=k2[i-1]*2%mod;
	C[0][0]=1;for(int i=1;i<=50;i++){C[i][0]=1;for(int j=1;j<=i;j++) C[i][j]=(C[i-1][j-1]+C[i-1][j])%mod;}
	printf("%lld\n",F(n,m)*qpow(k2[n*m],mod-2)%mod);
	return 0;
}

B. Simple

Let \ (f(n) \) represent the number of conditions satisfied with the length of \ (n \)

Then the requirement is \ (\ sum \ limits {I = 1} ^ Ni ^ 2 \ times f (I) \)

Considering how to find \ (f(n) \), it is found that only when the cyclic section of \ (n \) is not \ (n \), it cannot contribute. For the remaining strings, only the smallest dictionary will contribute

The length of the loop section can only be a factor of \ (n \), so it can be excluded

There are \ (10^{\frac{n}{d} \) strings that loop \ (d \) times. Just use Mobius function

\(f(n)=\frac{\sum\limits_{d|n}\mu(d)10^{\frac{n}{d}}}{n}\)

The answer becomes \ (\ sum \ limits {I = 1} ^ {n} I ^ 2 \ frac {\ sum \ limits {D | I} \ mu (d) 10 ^ {\ frac {I} {D}} {I} \)

\(\sum\limits_{i=1}^ni\sum\limits_{d|i}\mu(d)10^{\frac{i}{d}}\)

Enumeration factor becomes

\(\sum\limits_{d=1}^nd\mu(d)\sum\limits_{i=1}^{\left \lfloor \frac{n}{d} \right \rfloor}i10^i\)

In the front, a \ (id \) is processed by Du Jiao's screen, and in the back, an equal difference is multiplied by equal ratio, and the general term is obtained by dislocation multiplication, which is solved by fast power

Code
#include<bits/stdc++.h>
#define int long long
#define rint signed
#define mod 258280327
#define i2 129140164
#define i81 255091681
#define inf 0x3f3f3f3f3f3f3f3f
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*f;
}
int n,ans;
rint prime[10000010],mu[10000010],cnt;
bool is[10000010];
int smu[10000010];
unordered_map<int,int>Smu;
inline int qpow(int x,int k){
	int res=1,base=x;
	while(k){if(k&1) res=res*base%mod;base=base*base%mod;k>>=1;}
	return res;
}
inline int s(int x){x%=mod;return x*(x+1)%mod*i2%mod;}
inline int S(int x){return ((9*x%mod-1+mod)%mod*qpow(10,x)%mod+1)*i81%mod*10%mod;}
int getsmu(int n){
	if(n<=10000000) return smu[n];
	if(Smu.find(n)!=Smu.end()) return Smu[n];
	int sum=1;
	for(int l=2,r;l<=n;l=r+1){
		r=n/(n/l);
		sum=(sum-(s(r)-s(l-1)+mod)%mod*getsmu(n/l)%mod+mod)%mod;
	}
	return Smu[n]=sum;
}
signed main(){
#ifdef LOCAL
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
	mu[1]=1;for(int i=2;i<=10000000;i++){
		if(!is[i]) prime[++cnt]=i,mu[i]=-1;
		for(int j=1;j<=cnt&&i*prime[j]<=10000000;j++){
			is[i*prime[j]]=1;
			if(i%prime[j]==0) break;
			mu[i*prime[j]]=-mu[i];
		}
	}
	for(int i=1;i<=10000000;i++) smu[i]=(smu[i-1]+mu[i]*i%mod+mod)%mod;
	n=read();
	for(int l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		ans=(ans+S(n/l)*(getsmu(r)-getsmu(l-1)+mod)%mod)%mod;
	}
	printf("%lld\n",ans);
	return 0;
}

C. mate

You can directly enumerate a few steps in a certain direction, and then the rest can be calculated

Let \ (u,d,l,r \) represent several steps up, down, left and right respectively

The answer is \ (\ sum \ limits {u = 0} ^ {n} \ frac {n!} {u!d!l!r!}\)

Pay attention to judge whether it is legal

Then it is found that the modulus is not necessarily a prime number, so use the idea similar to \ (exLucas \) to find the combination number to find the factorial, and then combine it with \ (CRT \)

Although I directly convert the above formula into three combinatorial numbers, the principle is the same

Topics: number theory