题目:
http://acm.hdu.edu.cn/showproblem.php?pid=6198
题意:
如果一个数字
n
可以等于
思路:
可以推出规律,当
k=1
时,答案为
4
,当
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 10 + 10;
const ll mod = 998244353;
struct matrix
{
int row, col;
ll mat[N][N];
matrix(int _row=0, int _col=0)
{
init(_row, _col);
}
void init(int _row, int _col)
{
row = _row, col = _col;
memset(mat, 0, sizeof mat);
}
matrix operator* (matrix b)
{
matrix c(row, b.col);
for(int i = 1; i <= row; i++)
for(int j = 1; j <= b.col; j++)
for(int k = 1; k <= col; k++)
c.mat[i][j] = (c.mat[i][j] + mat[i][k] * b.mat[k][j] % mod) % mod;
return c;
}
};
matrix mod_pow(matrix a, ll b, ll p)
{
matrix ans(2, 2);
ans.mat[1][1] = ans.mat[2][2] = 1;
while(b)
{
if(b & 1) ans = ans * a;
a = a * a;
b >>= 1;
}
return ans;
}
int main()
{
int k;
while(~ scanf("%d", &k))
{
k = 4 + 2*k - 1;
matrix a(2, 2);
a.mat[1][1] = 1, a.mat[1][2] = 1;
a.mat[2][1] = 1, a.mat[2][2] = 0;
a = mod_pow(a, k, mod);
printf("%lld\n", a.mat[1][2] - 1);
}
return 0;
}