标签:typedef play 个数 task tin sizeof ons tis 组成
1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 const int maxn=15; 7 typedef long long ll; 8 ll n=7,mod; 9 ll e[maxn][maxn],v[maxn][maxn],w[maxn][maxn]; 10 void mul(ll a[maxn][maxn],ll b[maxn][maxn]) 11 { 12 13 memset(e,0,sizeof(e)); 14 for(ll i=1;i<=n;++i) 15 { 16 for(ll j=1;j<=n;++j) 17 { 18 ll sum=0; 19 for(ll k=1;k<=n;++k) 20 { 21 sum=(sum%mod+(a[i][k]*b[k][j])%mod)%mod; 22 } 23 e[i][j]=sum; 24 } 25 } 26 for(ll i=1;i<=n;++i) 27 { 28 for(ll j=1;j<=n;++j) 29 { 30 a[i][j]=e[i][j]; 31 } 32 } 33 } 34 void pow(ll b) 35 { 36 for(ll i=1;i<=n;++i) 37 { 38 w[i][i]=1; 39 } 40 while(b) 41 { 42 if(b&1) 43 { 44 mul(w,v); 45 } 46 mul(v,v); 47 b>>=1; 48 } 49 } 50 int main() 51 { 52 ll a,b; 53 while(~scanf("%lld%lld",&a,&b)) 54 { 55 mod = b; 56 memset(w,0,sizeof(w)); 57 memset(v,0,sizeof(v)); 58 if(a==1) 59 { 60 int c=2%mod; 61 printf("%d\n",c); 62 continue; 63 } 64 else if(a==2) 65 { 66 int c=4%mod; 67 printf("%d\n",c); 68 continue; 69 } 70 else if(a==3) 71 { 72 int c=6%mod; 73 printf("%d\n",c); 74 continue; 75 } 76 else if(a==4) 77 { 78 int c=9%mod; 79 printf("%d\n",c); 80 continue; 81 } 82 else if(a==0) 83 { 84 printf("0\n"); 85 continue; 86 } 87 //0 2 4 6 9 88 v[1][1]=1;v[1][2]=0;v[1][3]=1;v[1][4]=1; 89 v[2][1]=1;v[2][2]=0;v[2][3]=0;v[2][4]=0; 90 v[3][1]=0;v[3][2]=1;v[3][3]=0;v[3][4]=0; 91 v[4][1]=0;v[4][2]=0;v[4][3]=1;v[4][4]=0; 92 pow(a-4); 93 ll sum=(w[1][1]*9+w[1][2]*6+w[1][3]*4+w[1][4]*2)%mod; 94 printf("%lld\n",sum); 95 } 96 return 0; 97 }
标签:typedef play 个数 task tin sizeof ons tis 组成
原文地址:https://www.cnblogs.com/kongbursi-2292702937/p/10996819.html