模板题==而且数都不用自己改
推导出来这玩意这题就快结束了*^_^* 带上模板 完美1A
#include <iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX=3;
long Mod=1000000000;
typedef struct{
long long m[MAX][MAX];
}Matrix;
Matrix P={1,1,0,1,0,0,1,1,1};
Matrix I={1,0,0,0,1,0,0,0,1};
Matrix matrixmul(Matrix a,Matrix b)
{
int i,j,k;
Matrix c;
for(i=0;i<MAX;i++)
for(j=0;j<MAX;j++)
{
c.m[i][j]=0;
for(k=0;k<MAX;k++)
{
a.m[i][k]=(a.m[i][k]%Mod+Mod)%Mod;
b.m[k][j]=(b.m[k][j]%Mod+Mod)%Mod;
c.m[i][j]+=(a.m[i][k]*b.m[k][j])%Mod;
}
c.m[i][j]=(c.m[i][j]%Mod+Mod)%Mod;
}
return c;
}
Matrix quickpow(long long n)
{
Matrix m=P,b=I;
while(n>=1)
{
if(n&1) b=matrixmul(b,m);
n=n>>1;
m=matrixmul(m,m);
}
return b;
}
int main()
{
long long a,b;
while(~scanf("%lld%lld",&a,&b))
{
if(a==0&&b==0) break;
Matrix aa,bb;
long long asum,bsum;
if(a==0) asum=0;
else if(a==1) asum=1;
else if(a==2) asum=2;
else
{
aa=quickpow(a-2);
asum=aa.m[2][0]%Mod+aa.m[2][1]%Mod+(aa.m[2][2]*2)%Mod;
asum=(asum)%Mod;
}
if(b==0) bsum=1;
else if(b==1) bsum=2;
else
{
bb=quickpow(b-1);
bsum=bb.m[2][0]%Mod+bb.m[2][1]%Mod+(bb.m[2][2]*2)%Mod;
bsum%=Mod;
}
bsum=((bsum-asum)+Mod)%Mod;///
printf("%lld\n",bsum);
}
return 0;
}