首先是DP,分段DP(按位数讨论) 然后每一段构造出它对应的矩阵,用矩阵快速幂加速 type matrix=..,..]of int64; var n,m:int64; a,b,c,d:matrix; function min(x,y:int64):int64; begin if x<y then exit(x); exit(y); end; procedure cheng(var a,b:matrix); var i,j,k:longint; begin do do d[i,j]:=; do…