POJ3070 斐波那契數列遞推 矩陣快速冪模板題

2022-06-06 03:48:11 字數 511 閱讀 3446

題目分析:

對於給出的n,求出斐波那契數列第n項的最後4為數,當n很大的時候,普通的遞推會超時,這裡介紹用矩陣快速冪解決當遞推次數很大時的結果,這裡矩陣已經給出,直接計算即可

1 #include2 #include3

using

namespace

std;45

const

int mod = 10000;6

struct

mat;

910 mat operator * (mat a, mat b)

19 ret.m[i][j] =temp;20}

21}

22return

ret;23}

2425 mat pow_mat(mat a, int n)

32return

res;33}

3435

intmain()51}

52return0;

53 }

POJ3070 斐波那契數列 矩陣快速冪

題意就是讓你求斐波那契數列,不過n非常大,只能用logn的矩陣快速冪來做了 剛學完矩陣快速冪刷的水題,poj不能用萬能標頭檔案是真的煩 include include include include using namespace std typedef long long ll const int...

POJ 3070 矩陣快速冪求斐波那契數列

方法一 矩陣快速冪取模求斐波那契數列 include include define maxn 10000 using namespace std struct matrix m matrix mul matrix a,matrix b matrix mtpow matrix a,int k int ...

1188 斐波那契數列 2 (遞推)

1188 斐波那契數列 2 遞推 時間限制 1000 ms 記憶體限制 65536 kb 提交數 18578 通過數 6605 題目描述 菲波那契數列是指這樣的數列 數列的第乙個和第二個數都為1,接下來每個數都等於前面2個數之和。給出乙個正整數a,要求菲波那契數列中第a個數對1000取模的結果是多少...