#include<iostream>
#include<cstring>
#include<math.h>
using namespace std;
int n,m,p;
int len=2;
struct node{
int mat[2][2];
}x,y,k;
void init()
{
x.mat[0][0]=1;
x.mat[0][1]=1;
x.mat[1][0]=1;
x.mat[1][1]=0;
x.mat[0][0]=1;
x.mat[0][1]=0;
y.mat[1][0]=0;
y.mat[1][1]=1;
}
node mul(node x,node y)
{
node temp;
for(int i=0;i<len;i++)
{
for(int j=0;j<len;j++)
{
temp.mat[i][j]=0;
for(int k=0;k<len;k++)
temp.mat[i][j]+=x.mat[i][k]+y.mat[k][j];
}
}
return temp;
}
node mul_pow(node x,node y,int n)
{
while(n)
{
if(n&1)
y=mul(y,x);
x=mul(x,x);
n=n>>1;
}
return y;
}
int main()
{
cin>>n>>m>>p;
init();
int sum=0;
int temp=0;
for(int i=1;i<n-1;i++)
{
k=mul_pow(x,y,i);
if(i==m-2)
temp=k.mat[0][0]+k.mat[0][1];
cout<<"k.mat[0][0]+k.mat[0][1]="<<k.mat[0][0]+k.mat[0][1]<<endl;
sum+=(k.mat[0][0]+k.mat[0][1])%p;
}
sum=sum%temp;
cout<<temp<<endl;
cout<<sum<<endl;
return 0;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/87359.html
標籤:C++ 語言
上一篇:release版本的dll,運行時提示找不到程式輸入點
下一篇:視差圖如何使用,測出最終距離
