Nanchang icpc H network trials title K binary matrix rapid acceleration power

https://nanti.jisuanke.com/t/41355

A fast power matrix, but obviously make life difficult, $ 1e7 * log (1e18) $, the matrix is ​​very small.

Then start optimizing:

1. Fibonacci and like to play table can be found under modulo arithmetic, cycling festival for the $ 499 122 176 $, fast power from $ 1e7 * log (1e18) $ becomes $ 1e7 * log (4e8) $ faster some

2. The fast power and the like, we find that, if the pre-$ 1,2, .... sqrt (499122176) coefficient matrix and $ sqrt (499122176) -1 $ under power, 2sqrt (499122176) .. sqrt ( 499122176) * (sqrt (499122176) -1)) in the coefficient matrix power $

Then we can quickly Couchu any of a coefficient matrix we need,

Ah, it is $ O (1) $ to get the final complexity $ 1e7 + 5e4 $

Also can run ...

#include<bits/stdc++.h>
using namespace std;
const int mod=998244353,mxpw=22400;
struct node {int a,b,c,d;}m_pow[2][mxpw],tmp,xishu={3,2,1,0};
inline node mul(const node &x,const node &y) {
  return {(1ll*x.a*y.a+1ll*x.b*y.c)%mod,(1ll*x.a*y.b+1ll*x.b*y.d)%mod,
          (1ll*x.c*y.a+1ll*x.d*y.c)%mod,(1ll*x.c*y.b+1ll*x.d*y.d)%mod};
}
int getans(int n) {return mul(m_pow[0][n%mxpw],m_pow[1][n/mxpw]).a;}
signed main() {
  m_pow[0][0]=m_pow[1][0]={1,0,0,1};
  for(int j=1;j<=mxpw-1;++j) m_pow[0][j]=mul(m_pow[0][j-1],xishu);
  m_pow[1][1]=mul(m_pow[0][mxpw-1],xishu);
  for(int j=2;j<=mxpw-1;++j) m_pow[1][j]=mul(m_pow[1][j-1],m_pow[1][1]);
  int years = 0, q, res; long long n; cin >> q >> n; 
  while(q--) {
    getans res = (n% 499122176-1); 
    years = ^ res;	
    n ^ = (1ll * res * res); 
  } 
  Cout << years; 
}

 

Guess you like

Origin www.cnblogs.com/nervendnig/p/11489482.html