当前位置:网站首页>[acnoi2022] I have done it, but I can't

[acnoi2022] I have done it, but I can't

2022-06-24 08:23:00 OneInDark

subject

Background
The rolling master's knife has reached his throat ; A flash of cold light ; I saw blood spattering . My body fell uncontrollably to the ground ……

I woke up from reality .“ Fortunately, it doesn't happen in the dream world .” I take a long breath .

Title Description
seek n × n n\times n n×n matrix A A A The determinant of , among
A i , j = { 1 ( i = j ) 0 ( i ≠ j ∧ i ∣ j ) C ( otherwise ) A_{i,j}=\begin{cases}1 & (i=j)\\0 & (i\ne j\land i\mid j)\\ C & (\text{otherwise}) \end{cases} Ai,j=10C(i=j)(i=jij)(otherwise)

Yes 998244353 998244353 998244353 modulus .

Data range and tips
n ⩽ 1 0 11 n\leqslant 10^{11} n1011 . time limit 6 s \rm 6s 6s .

Ideas

Simple deduction det ⁡ \det det The way : Subtract the previous line from the next line , Become Heisenberg matrix .

Complex method : Place diagonal 1 1 1 Regard as C + ( 1 − C ) C+(1-C) C+(1C), Enumerate which locations are selected ( 1 − C ) (1-C) (1C), Then the remaining part is the main subformula .

lemma : If and only if the row and column numbers reserved by the primary and secondary formulas { x i } \{x_i\} { xi} Satisfy x 1 ∣ x 2 ∣ x 3 ∣ ⋯ ∣ x k x_1\mid x_2\mid x_3\mid\cdots\mid x_k x1x2x3xk when , Its d e t \rm det det yes C k C^k Ck, It is 0 0 0 .

prove : Each line has only one true suffix of all zeros , The rest is C C C . So it must be a lower triangular matrix , At this time, there is a multiple relationship between two pairs .

□ \square

thus , We number the unselected rows and columns d p \tt dp dp, It is easy to write a transfer
f ( n ) = C ( 1 − C ) n − 1 + ∑ d ∣ n f ( d ) ( 1 − C ) n − d − 1 C f(n)=C(1-C)^{n-1}+\sum_{d\mid n}f(d)(1-C)^{n-d-1}C f(n)=C(1C)n1+dnf(d)(1C)nd1C

as well as
a n s = ( 1 − C ) n + ∑ i = 1 n f ( i ) ( 1 − C ) n − i ans=(1-C)^n+\sum_{i=1}^{n}f(i)(1-C)^{n-i} ans=(1C)n+i=1nf(i)(1C)ni

Deform a little
f ( n ) ( 1 − C ) − n = C 1 − C + ∑ d ∣ n C 1 − C ( f ( d ) ( 1 − C ) − d ) f(n)(1-C)^{-n}=\frac{C}{1-C}+\sum_{d\mid n}\frac{C}{1-C}(f(d)(1-C)^{-d}) f(n)(1C)n=1CC+dn1CC(f(d)(1C)d)

Brief notes v : = C 1 − C v:=\frac{C}{1-C} v:=1CC, Might as well set C ≠ 1 C\ne 1 C=1 . Syncopation g ( n ) : = f ( n ) ( 1 − C ) − n g(n):=f(n)(1-C)^{-n} g(n):=f(n)(1C)n .
g ( n ) = v + ∑ d ∣ n d ≠ n v ⋅ g ( d ) (1) g(n)=v+\sum_{d\mid n}^{d\ne n}v\cdot g(d)\tag{1} g(n)=v+dnd=nvg(d)(1)

a n s = ( 1 − C ) n ∑ i = 1 n g ( i ) ans=(1-C)^n\sum_{i=1}^{n}g(i) ans=(1C)ni=1ng(i)

be aware g ( i ) g(i) g(i) It's not an integral function , I began to think , I'm going to write about the quality factor index g ( i ) g(i) g(i) The expression of .

Cerebral pumping

set up n = ∏ p i t i n=\prod p_i^{t_i} n=piti, remember
λ l : = ∏ ( l − 1 + t i t i ) \lambda_l:=\prod{l-1+t_i\choose t_i} λl:=(til1+ti)

That is, the exponential descent scheme of a single qualitative factor , In the long for l l l On the chain . Inclusion and exclusion to ensure that every step really drops .
α l : = ∑ i = 0 l − 1 ( l − 1 i ) ( − 1 ) i λ l − i \alpha_l:=\sum_{i=0}^{l-1}{l-1\choose i}(-1)^i\lambda_{l-i} αl:=i=0l1(il1)(1)iλli

g ( n ) = ∑ i = 1 log ⁡ n α i v i = ∑ i = 1 log ⁡ n v i ∑ j = 0 i − 1 ( i − 1 j ) ( − 1 ) j λ i − j = ∑ i = 1 log ⁡ n v i ∑ j = 0 i − 1 ( i − 1 j ) ( − 1 ) j ∏ ( i − j − 1 + t k t k ) = ∑ l ( ∑ i = l + 1 log ⁡ n v i ( i − 1 i − l − 1 ) ( − 1 ) i − l − 1 ) ∏ ( l + t k t k ) = ∑ l β l ⋅ I l + 1 ( n ) \begin{aligned} g(n)&=\sum_{i=1}^{\log n}\alpha_iv^i=\sum_{i=1}^{\log n}v^i\sum_{j=0}^{i-1}{i-1\choose j}(-1)^j\lambda_{i-j}\\ &=\sum_{i=1}^{\log n}v^i\sum_{j=0}^{i-1}\binom{i-1}{j}(-1)^j\prod{i-j-1+t_k\choose t_k}\\ &=\sum_{l}\left(\sum_{i=l+1}^{\log n}v^i{i-1\choose i-l-1}(-1)^{i-l-1}\right)\prod{l+t_k\choose t_k}\\ &=\sum_{l}\beta_l\cdot I^{l+1}(n) \end{aligned} g(n)=i=1lognαivi=i=1lognvij=0i1(ji1)(1)jλij=i=1lognvij=0i1(ji1)(1)j(tkij1+tk)=l(i=l+1lognvi(il1i1)(1)il1)(tkl+tk)=lβlIl+1(n)

I l + 1 I^{l+1} Il+1 finger ( l + 1 ) (l{+}1) (l+1) individual I I I The result of the Dirichlet convolution of . So you can O ( log ⁡ n ) \mathcal O(\log n) O(logn) Solve the problem by secondary screening , Such as Du Jiao sieve or min25 \texttt{min25} min25 .

Positive solution

Duchenne sieves are not based on integral functions . and ,“ Sum the values of the factors ” Not like Dirichlet convolution ? It's not like divide and conquer FTT \textit{FTT} FTT Do you ?

in fact , ( 1 ) (1) (1) Find the prefix and sum at the same time on both sides of the formula, and there is
⇒ S ( n ) = v n + ∑ i = 2 n v ⋅ S ( ⌊ n / i ⌋ ) \Rightarrow S(n)=vn+\sum_{i=2}^{n}v\cdot S(\lfloor n/i\rfloor) S(n)=vn+i=2nvS(n/i)

among S ( n ) = ∑ i ⩽ n g ( i ) S(n)=\sum_{i\leqslant n}g(i) S(n)=ing(i) . So Du taught me to sift . Time complexity O ( n 2 / 3 ) \mathcal O(n^{2/3}) O(n2/3) Of …… Do you ?

Note that non integrable functions cannot be strictly linear sieves . Need to optimize . in fact , The exponents of prime factors are the same as the resettable ones , g g g Is obviously the same . So we only have a few values to enumerate factors . But how to find the corresponding relationship ?

One way is hash \texttt{hash} hash . Of course, we can also change the linear sieve , Each number records its maximum prime factor and number , And preprocess the power of each prime number . Then save f i f_i fi by , And i i i Among the numbers that have the same exponentially resettable , The smallest one . Ask directly f i f_i fi trouble , You can ask for j j j bring f i = f j f_i=f_j fi=fj . set up i i i After removing the maximum prime factor, we get u u u, if f u ≠ u f_u\ne u fu=u be j = i u f u j=\frac{i}{u}f_u j=uifu, Otherwise, judge the number of index and prime factor .

In the end only 500 + 500+ 500+ The number needs to be calculated violently , So the complexity is O ( n 2 / 3 ) \mathcal O(n^{2/3}) O(n2/3) 了 .

Code

#include <cstdio>
#include <algorithm> // Almighty XJX yyds!!
#include <cstring> // oracle: ZXY yydBUS!!!
#include <cctype> // I hate rainybunny.
using llong = long long;
# define rep(i,a,b) for(int i=(a); i<=(b); ++i)
# define drep(i,a,b) for(int i=(a); i>=(b); --i)
# define rep0(i,a,b) for(int i=(a); i!=(b); ++i)
inline int readint(){
    
	int a = 0, c = getchar(), f = 1;
	for(; !isdigit(c); c=getchar()) if(c == '-') f = -f;
	for(; isdigit(c); c=getchar()) a = a*10+(c^48);
	return a*f;
}

const int LOGN = 40, MOD = 998244353;
inline llong qkpow(llong b, int q){
    
	llong a = 1;
	for(; q; q>>=1,b=b*b%MOD) if(q&1) a = a*b%MOD;
	return a;
}

const int MAXN = 23544347;
bool isPrime[MAXN]; int* ppow[MAXN];
int primes[MAXN], primes_size, g[MAXN];
int fa[MAXN], big[MAXN], num[MAXN], nxt[MAXN], cnt[MAXN];
void dfs(int &res, int x, int y){
    
	if(x == 1){
     if(g+y != &res){
     res = (res+g[y])%MOD; } return; }
	rep(i,0,num[x]) dfs(res,nxt[x],y), y *= big[x];
}
void sieve(const int &v, int n = MAXN-1){
    
	memset(isPrime+2, true, n-1);
	fa[1] = 1, g[1] = v;
	for(int i=2,&len=primes_size; i<=n; ++i){
    
		if(isPrime[i]){
    
			primes[++len] = big[i] = i, cnt[i] = 1;
			num[i] = 1, fa[i] = 2, nxt[i] = 1;
			g[i] = int(llong(v+1)*v%MOD);
			for(int j=2,p=i; true; ++j,p*=i)
				if(p > n/i){
     ppow[i] = new int[j]; break; }
			for(int j=0,p=1; p<=n/i; ++j,p*=i,ppow[i][j]=p);
		}
		else{
    
			const int rt = fa[nxt[i]];
			if(rt != nxt[i]) g[i] = g[fa[i] = fa[rt*(i/nxt[i])]];
			else if(big[i] != primes[cnt[rt]+1]){
     // not nearest
				fa[i] = rt*ppow[primes[cnt[rt]+1]][num[i]];
				fa[i] = fa[fa[i]], g[i] = g[fa[i]];
			}
			else if(rt != 1 && num[rt] < num[i]){
    
				fa[i] = nxt[rt]*ppow[big[rt]][num[i]]
					*ppow[big[i]][num[rt]]; // switch
				fa[i] = fa[fa[i]], g[i] = g[fa[i]];
			}
			else{
     // I am smallest
				static int wxk = 0; ++ wxk;
				fa[i] = i, dfs(g[i],i,1);
				g[i] = int(llong(g[i]+1)*v%MOD);
			}
		}
		for(int j=1; j<=len; ++j){
    
			const int to = i*primes[j]; if(to > n) break;
			isPrime[to] = false, big[to] = big[i];
			if(!(i%primes[j])){
    
				if(nxt[i] == 1) num[to] = num[i]+1, nxt[to] = 1;
				else num[to] = num[i], nxt[to] = nxt[i]*primes[j];
				cnt[to] = cnt[i]; break;
			}
			num[to] = num[i], nxt[to] = nxt[i]*primes[j], cnt[to] = cnt[i]+1;
		}
	}
}

int res[4650];
int getSum(const llong &n, const int &v, llong x){
    
	if(x < MAXN) return g[x];
	int &w = res[n/x]; if(~w) return w;
	w = int(x%MOD); // easiest
	for(llong l=2,r,val; l!=x+1; l=r){
    
		val = x/l, r = x/val+1; // move
		w = int((w+(r-l)%MOD*getSum(n,v,val))%MOD);
	}
	return w = int(llong(w)*v%MOD);
}

int main(){
    
	llong n; scanf("%lld",&n); int c = readint();
	if(c == 1){
     puts(n <= 2 ? "1" : "0"); return 0; }
	int v = int(c*qkpow(1-c+MOD,MOD-2)%MOD);
	sieve(v); rep0(i,2,MAXN) g[i] = (g[i]+g[i-1])%MOD;
	memset(res, -1, sizeof(res));
	int ans = getSum(n,v,n)+1;
	ans = int(ans*qkpow(1+MOD-c,int(n%(MOD-1)))%MOD);
	printf("%d\n",ans);
	return 0;
}
原网站

版权声明
本文为[OneInDark]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/175/202206240440493993.html