题目传送门
/*
矩阵快速幂:求第n项的Fibonacci数,转置矩阵都给出,套个模板就可以了。效率很高啊
*/
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int MAXN = 1e3 + ;
const int INF = 0x3f3f3f3f;
const int MOD = ;
struct Mat {
int m[][];
};
Mat multi_mod(Mat a, Mat b) {
Mat ret; memset (ret.m, , sizeof (ret.m));
for (int i=; i<; ++i) {
for (int j=; j<; ++j) {
for (int k=; k<; ++k) {
ret.m[i][j] = (ret.m[i][j] + a.m[i][k] * b.m[k][j]) % MOD;
}
}
}
return ret;
}
int matrix_pow_mod(Mat x, int n) {
Mat ret; ret.m[][] = ret.m[][] = ; ret.m[][] = ret.m[][] = ;
while (n) {
if (n & ) ret = multi_mod (ret, x);
x = multi_mod (x, x);
n >>= ;
}
return ret.m[][];
}
int main(void) { //POJ 3070 Fibonacci
int n;
while (scanf ("%d", &n) == ) {
if (n == -) break;
Mat x;
x.m[][] = x.m[][] = x.m[][] = ; x.m[][] = ;
printf ("%d\n", matrix_pow_mod (x, n));
}
return ;
}