class="markdown_views prism-atom-one-light">
传送门
题目大意:
给定一个斐波那契数列
Fn,让你求
FFn
解题思路:
首先我们将
Fn 的循环节找到, 然后套一下矩阵快速幂模的是
MOD1,那么底数就变成了比较小的一个数(不至于太大),然后在套一下矩阵快速幂这次是模
MOD。
My Code:
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int MAXN = 2;
const LL MOD = 20160519LL;
const LL MOD1 = 26880696LL;
LL fib[MOD1+5], fib1[MOD1+5];
void Init(){
fib[0] = 0, fib[1] = 1;
for(int i=2; i5; i++)
fib[i] = (fib[i-1] + fib[i-2])% MOD;
}
typedef struct
{
LL mat[MAXN][MAXN];
} Matrix;
Matrix p = {1, 1,
1, 0,
};
Matrix I = {1, 0,
0, 1,
};
Matrix Mul_Matrix(Matrix a, Matrix b, LL MOD)
{
Matrix c;
for(int i=0; ifor(int j=0; j0;
for(int k=0; kreturn c;
}
Matrix quick_Mod_Matrix(LL m, LL MOD)
{
Matrix ans = I, b = p;
while(m)
{
if(m & 1)
ans = Mul_Matrix(ans, b, MOD);
m>>=1;
b = Mul_Matrix(b, b, MOD);
}
return ans;
}
LL quick_Mod(LL a, LL b, LL MOD)
{
LL ans = 1;
while(b)
{
if(b & 1)
ans = (ans * a) % MOD;
b>>=1;
a = (a * a) % MOD;
}
return ans;
}
int main()
{