Matrix Fast Power, 1001. Fibonacci 2 seek Fibonacci nth! After all, the amount of data is too large!
http://soj.sysu.edu.cn/show_problem.php?pid=1001&cid=1740
1#include <iostream>2#include <cstring>3 4 using namespacestd;5 6 structMat {7 Long Longm[2][2];8 Mat ()9 {TenMemset (M,0,sizeof(m)); One } A }; - - intn=2; the -Matoperator*(Mat A, mat b) - { - Mat C; + for(intI=0; i<n; i++) - for(intj=0; j<n; J + +) + for(intk=0; k<n; k++) AC.M[I][J] + = (a.m[i][k] * b.m[k][j])%1000000007;//Remember Mold at returnC; - } - - voidPrint (Mat a) - { - for(intI=0; i<n; i++) in { - for(intj=0; j<n; J + +) tocout << A.m[i][j] <<" "; +cout <<Endl; - } the } * $ intMain ()Panax Notoginseng { - intT; the while(Cin >>t) + { A if(t = =-1) the Break; + Mat A; - Mat C; $c.m[0][0] =1; c.m[0][1] =0; c.m[1][0] =0; c.m[1][1] =1; $a.m[0][0] =1; a.m[0][1] =1; a.m[1][0] =1; a.m[1][1] =0; - intN =T; - while(N) the { - if(N%2) Wuyic = c *A; theA = A *A; -N/=2; Wu } -cout << c.m[0][1]%1000000007<<Endl; About } $ - return 0; -}
Sicily Fibonacci 2