标签:
题目地址:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=5383
思路:
type arr=array[1..2,1..2] of int64; var x,p:int64; a,b,c,w:arr; cas,i,t:longint; procedure mul(var a,b,c:arr); var i,j,k,n:longint; begin n:=2; fillchar(w,sizeof(w),0); for i:=1 to n do for j:=1 to n do for k:=1 to n do w[i][j]:=(w[i][j]+a[i][k]*b[k][j]) mod p; for i:=1 to n do for j:=1 to n do c[i][j]:=w[i][j]; end; begin readln(cas); p:=1000000000; for i:=1 to cas do begin read(t); readln(x); a[1,1]:=0;a[1,2]:=1;a[2,1]:=0;a[2,2]:=0; b[1,1]:=0;b[1,2]:=1;b[2,1]:=1;b[2,2]:=1; while (x<>0) do begin if x mod 2=1 then mul(a,b,a); x:=x div 2; mul(b,b,b); end; write(t); write(' '); writeln(a[1][1]); end; end.
UVAlive 7361 Immortal Porpoises(矩阵快速幂)
标签:
原文地址:http://blog.csdn.net/wang2147483647/article/details/52235119