http://blog.csdn.net/wust_xhj/article/details/47779539
How to push it, look here.
F[0]=0
F[1]=1
[0,1]* | 0 Q | (n-1) =[f (n-1), f (n)]
| 1 q-1|
Run Fast Power
#include <stdio.h>#include<string.h>#include<algorithm>#include<math.h>using namespaceStd;typedefLong Longll;#defineMAXN 105structnode{ll z[3][3];}; ll Quick (ll a,ll b,ll c) {ll ans=1; while(b>0) { if(b%2==1) ans= (ans*a)%C; b/=2; A= (a*a)%C; } returnans;} ll P;node mou (node A,node b) {node C; for(intI=0;i<2; i++) { for(intj=0;j<2; j + +) {ll sum=0; for(intk=0;k<2; k++) Sum= (Sum+a.z[i][k]*b.z[k][j])%p; C.Z[I][J]=sum; } } returnC;}intMain () {ll x1,y1,z1,y2,z2; while(SCANF ("%lld%lld%lld", &X1,&Y1,&Z1)! =EOF) { if(x1==-1&&y1==-1&&z1==-1) Break; scanf ("%lld%lld%lld",&y2,&z2,&p); LL Q= (Quick (x1,y1,p) +z1)%p; Node S,a,ans; ans.z[0][0]=1; ans.z[0][1]=0; ans.z[1][0]=0; ans.z[1][1]=1; a.z[0][0]=0; a.z[0][1]=Q; a.z[1][0]=1; a.z[1][1]=q-1; S=A; while(z2>0) { if(z2%2==1) ans=mou (ans,a); Z2=z2/2; A=mou (a,a); } for(intI=0; i<y2;i++) {ans=mou (S,ans); S=mou (s,s); } printf ("%d\n", ans.z[1][1]); } return 0;}
Recursive HDU 3411