Ideas:
Matrix Fast power.
Realize:
1#include <iostream>2#include <cstdio>3#include <vector>4 using namespacestd;5 6typedefLong Longll;7typedef vector<ll>Vec;8typedef vector<vec>Mat;9 Ten Const intMoD =99999999; One AMat Mul (Mat & A, Mat &b) - { -Mat C (A.size (), VEC (b[0].size ())); the for(inti =0; I < a.size (); i++) - { - for(intK =0; K < B.size (); k++) - { + for(intj =0; J < b[0].size (); J + +) - { +C[I][J] = (C[i][j] + a[i][k] * b[k][j])%MoD; A } at } - } - returnC; - } - - Mat Pow (Mat A, ll N) in { - Mat B (A.size (), VEC (A.size ())); to for(inti =0; I < a.size (); i++) + { -B[i][i] =1; the } * while(N >0) $ {Panax Notoginseng if(N &1) -b =Mul (b, a); theA =Mul (A, a); +N >>=1; A } the returnb; + } - $ intMain () $ { -Mat F (7, VEC (1)); -f[0][0] =6; thef[1][0] =1; -f[2][0] =2;Wuyif[3][0] =5; thef[4][0] =4; -f[5][0] =3; Wuf[6][0] =1; - ll N; AboutCIN >>N; $ if(N <=3) - { -printf"%d\n"+ a[3-n][0]); -printf"%d\n"+ a[5-(n1)][0]); A return 0; + } theMat X (7, VEC (7)); - for(inti =0; I <7; i++) $ { the for(intj =0; J <7; J + +) the { theX[I][J] =0; the } - } inx[0][2] =2; thex[0][3] =1; thex[0][6] =5; Aboutx[1][0] =1; thex[2][1] =1; thex[3][0] =1; thex[3][2] =3; +x[3][5] =2; -x[3][6] =3; thex[4][3] =1;Bayix[5][4] =1; thex[6][6] =1; theMat Res (7, VEC (7)); -res = POW (x, N-3); -Mat Fuck (7, VEC (1)); theFuck =Mul (res, F); theprintf"%d\n", fuck[0][0]); theprintf"%d\n", fuck[3][0]); the return 0; -}
Blue Bridge Cup algorithm improves the recursive value