当前位置:网站首页>[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=j∧i∣j)(otherwise)
Yes 998244353 998244353 998244353 modulus .
Data range and tips
n ⩽ 1 0 11 n\leqslant 10^{11} n⩽1011 . 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+(1−C), Enumerate which locations are selected ( 1 − C ) (1-C) (1−C), 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 x1∣x2∣x3∣⋯∣xk 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 .
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(1−C)n−1+d∣n∑f(d)(1−C)n−d−1C
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=(1−C)n+i=1∑nf(i)(1−C)n−i
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)(1−C)−n=1−CC+d∣n∑1−CC(f(d)(1−C)−d)
Brief notes v : = C 1 − C v:=\frac{C}{1-C} v:=1−CC, 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)(1−C)−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+d∣n∑d=nv⋅g(d)(1)
a n s = ( 1 − C ) n ∑ i = 1 n g ( i ) ans=(1-C)^n\sum_{i=1}^{n}g(i) ans=(1−C)ni=1∑ng(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:=∏(til−1+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=0∑l−1(il−1)(−1)iλl−i
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=1∑lognαivi=i=1∑lognvij=0∑i−1(ji−1)(−1)jλi−j=i=1∑lognvij=0∑i−1(ji−1)(−1)j∏(tki−j−1+tk)=l∑(i=l+1∑lognvi(i−l−1i−1)(−1)i−l−1)∏(tkl+tk)=l∑βl⋅Il+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=2∑nv⋅S(⌊n/i⌋)
among S ( n ) = ∑ i ⩽ n g ( i ) S(n)=\sum_{i\leqslant n}g(i) S(n)=∑i⩽ng(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;
}
边栏推荐
- Promise的使用场景
- os.path.join()使用过程中遇到的坑
- Getting started with crawler to giving up 06: crawler play Fund (with code)
- The applet reads more than 20 data, and the cloud function reads more than 100 restrictions
- Swift foundation features unique to swift
- 51单片机_外部中断 与 定时/计数器中断
- 小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
- Paper notes: multi label learning dm2l
- 权限模型 DAC ACL RBAC ABAC
- How to use the virtual clock of FPGA?
猜你喜欢
对于flex:1的详细解释,flex:1
WCF TCP protocol transmission
蓝桥杯_N 皇后问题
Future trends in automated testing
李白最经典的20首诗排行榜
Live broadcast review | detailed explanation of koordinator architecture of cloud native hybrid system (complete ppt attached)
Question bank and simulation examination for operation certificate of refrigeration and air conditioning equipment in 2022
Small sample fault diagnosis - attention mechanism code - Implementation of bigru code parsing
搜索与推荐那些事儿
1279_VMWare Player安装VMWare Tools时VSock安装失败解决
随机推荐
5g industrial router Gigabit high speed low delay
Atguigu---16-custom instruction
LINQ query (2)
The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain
小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
pyQt 常用系统的事件
2021-03-09 COMP9021第七节课笔记
[teacher zhaoyuqiang] use the Oracle tracking file
Swift 基礎 閉包/Block的使用(源碼)
自动化测试的未来趋势
js滚动div滚动条到底部
DHCP, TFTP Foundation
疫情下更合适的开发模式
LabVIEW查找n个元素数组中的质数
论文笔记: 多标签学习 DM2L
Swift 基础 闭包/Block的使用(源码)
Methods of vector operation and coordinate transformation
Serialization of unity
jwt(json web token)
Tool functions – get all files in the project folder