1 solutions
-
0
#include #include #include #include #include<math.h> using namespace std;
const long long mod=1000000007;
struct STU//结构体 { long long m[110][110]; } A,I;
long long n;
STU operator * (const STU &a,const STU &b)//重载运算符 { STU x;
memset(x.m,0,sizeof(x.m)); for(int i=1;i<=2;i++) { for(int j=1;j<=2;j++) { for(int k=1;k<=2;k++) { x.m[i][j]+=a.m[i][k]*b.m[k][j]%mod; x.m[i][j]%=mod; } } } return x;
} void init()//初始化 { memset(I.m,0,sizeof(I.m)); memset(A.m,0,sizeof(A.m)); I.m[1][1]=I.m[1][2]=1; A.m[1][1]=A.m[1][2]=A.m[2][1]=1; } int main(void) { cin>>n;
if(n<=2)//第一项或第二项的情况 cout<<1<<endl; return 0; } else //n>=3的情况 { n=n-2; while(n>0) //快速幂 { if(n%2!=0) I=I*A; A=A*A; n=n>>1; } cout<<I.m[1][1]<<endl;//输出 return 0; }
}
- 1
Information
- ID
- 913
- Time
- 1000ms
- Memory
- 128MiB
- Difficulty
- 4
- Tags
- # Submissions
- 4
- Accepted
- 2
- Uploaded By