これは、マトリックスの高速パワーのテンプレートです。
まず、転送行列の行数と列数をどのように記憶するか、最初に水平、次に垂直のハンドジェスチャーを作成しましょう。これは、応答行列の要素です。
したがって、最初の行列の列数は転送行列の水平方向の数に等しく、転送行列の列数は応答行列の列数に等しく...
#include <bits / stdc ++。h> #define db double #define ll long long #define reg register #define pb(x)push_back(x) #define fup(i、x、y)for(reg int i = x; i <= y; ++ i) #define fdw(i、x、y)for(reg int i = x; i> = y;-i) using namespace std; const int mod = 10000 ; int n; struct wy { ll a [ 5 ] [ 5 ]; wy(){memset(a、0、sizeof (a));} inline voidクリア() { memset(a、0、sizeof (a)); } wyフレンドオペレーター * (wy a、wy b) { wy c; FUP(I、1、2)FUP(J、1、2)FUP(K、1、2)CA [I] [J] =(CA [I] [J] + AA [I] [K] * BA [k] [j])%mod; cを返す; } WYフレンド演算子 ^ (WY A、LL Y) { wy c; fup(i、 21、)ca [i] [i] = 1 ; while (y) { if(y&1)c = c * a; y >> = 1 ; a = a * a; } return c; } } A、B、C; インラインint read() { int x = 0、ff = 1 ; char ch = getchar(); while(!isdigit(ch)){ if(ch == ' - ')ff = -1 ; ch = getchar();} while(isdigit(ch)){x =(x << 1)+(x << 3)+(ch ^ 48); ch = getchar(); } return x * ff; } int main() { freopen(" 1.in "、" r " 、stdin); Ba [ 1 ] [ 1 ] = 0 ; Ba [ 1 ] [ 2 ] = 1 ; Ba [ 2 ] [ 1 ] = 1; Ba [ 2 ] [2 ] = 1 ; while(1 ) { n = read(); if(n ==- 1)break ; if(n <= 2 ) { if(n == 0)puts(" 0 " ); それ以外はputs(" 1 " ); 続ける; } A.clear()。 Aa [ 1 ] [ 1 ] = 1 ; Aa [ 1 ] [ 2 ] = 1 ; C = B ^(n- 2 ); A = A * C; printf(" %lld \ n "、Aa [ 1 ] [ 2 ]); } 0を返し ます。 }