今天给大家献上“D”级题:LJX的校园:入学典礼!!
好的,以上就是LJX的校园:入学典礼的题目要求,现在献上代码!!!当当当!!!
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<iostream> #include<cstdio> #include<cstdlib> #include<cstring> #include<algorithm> #define MAXN 4 using namespace std; typedef long long int LL; int mod; struct matrix { LL p[MAXN][MAXN]; }ans,tmp; matrix operator*(matrix a,matrix b) { matrix c; for(int i=1;i<=3;i++) for(int j=1;j<=3;j++) { c.p[i][j]=0; for(int k=1;k<=3;k++) c.p[i][j]=(c.p[i][j]+((a.p[i][k]%mod)*(b.p[k][j]%mod))%mod)%mod; } return c; } void cal(LL t,LL last) { memset(tmp.p,0,sizeof(tmp.p)); tmp.p[1][1]=t; tmp.p[2][1]=tmp.p[3][1]=tmp.p[2][2]=tmp.p[3][2]=tmp.p[3][3]=1; LL y=last-t/10+1; while(y) { if(y&1) ans=ans*tmp; tmp=tmp*tmp; y>>=1; } } int main() { for(int i=1;i<=3;i++) ans.p[i][i]=1; LL n; scanf("%lld%lld",&n,&mod); LL t=10; while(n>=t) { cal(t,t-1); t*=10; } cal(t,n); printf("%lld ",ans.p[3][1]); return 0; }