2018 ACM 网络选拔赛 焦作赛区
A. Magic Mirror
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e2+10; 25 26 char s[maxn]; 27 28 int main() 29 { 30 int t,i; 31 scanf("%d",&t); 32 while (t--) 33 { 34 scanf("%s",s); 35 for (i=0;i<strlen(s);i++) 36 if (s[i]>='a' && s[i]<='z') 37 s[i]-=32; 38 if (strcmp(s,"JESSIE\0")==0) 39 printf("Good guy!\n"); 40 else 41 printf("Dare you say that again?\n"); 42 } 43 return 0; 44 }
B. Mathematical Curse
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e3+10; 25 26 ll a[maxn]; 27 ll f[10],l[10],r[10],LL=3e18,rr=-3e18; 28 int c[10]; 29 30 int main() 31 { 32 int t,n,m,i,j; 33 scanf("%d",&t); 34 while (t--) 35 { 36 scanf("%d%d%lld",&n,&m,&a[0]); 37 for (i=1;i<=n;i++) 38 scanf("%lld",&a[i]); 39 l[0]=r[0]=a[0]; 40 scanf("%c",&c[0]); 41 for (i=1;i<=m;i++) 42 { 43 scanf("%c",&c[i]); 44 l[i]=LL; 45 r[i]=rr; 46 } 47 48 for (j=1;j<=n;j++) 49 { 50 for (i=m;i>=1;i--) 51 { 52 switch(c[i]) 53 { 54 case '+': 55 if (l[i-1]!=LL) 56 l[i]=min(l[i],l[i-1]+a[j]); 57 if (r[i-1]!=rr) 58 r[i]=max(r[i],r[i-1]+a[j]); 59 break; 60 case '-': 61 if (l[i-1]!=LL) 62 l[i]=min(l[i],l[i-1]-a[j]); 63 if (r[i-1]!=rr) 64 r[i]=max(r[i],r[i-1]-a[j]); 65 break; 66 case '*': 67 if (l[i-1]!=LL) 68 l[i]=min(l[i],min(l[i-1]*a[j],r[i-1]*a[j])); 69 if (r[i-1]!=rr) 70 r[i]=max(r[i],max(l[i-1]*a[j],r[i-1]*a[j])); 71 break; 72 case '/': 73 if (a[j]!=0) 74 { 75 if (l[i-1]!=LL) 76 l[i]=min(l[i],min(l[i-1]/a[j],r[i-1]/a[j])); 77 if (r[i-1]!=rr) 78 r[i]=max(r[i],max(l[i-1]/a[j],r[i-1]/a[j])); 79 } 80 break; 81 } 82 } 83 } 84 printf("%lld\n",r[m]); 85 } 86 return 0; 87 } 88 /* 89 3 90 5 5 1000 91 1000 1000 1000 1000 1000 92 ***** 93 94 5 5 1000 95 -1000 -1000 -1000 -1000 -1000 96 ***** 97 */
E. Jiu Yuan Wants to Eat
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define ull unsigned long long 20 #define minv 1e-6 21 #define inf 1e9 22 #define pi 3.1415926536 23 #define nl 2.7182818284 24 const int maxn=1e5+10; 25 26 vector<int>e[maxn]; 27 int fa[maxn],num; 28 int dep[maxn],siz[maxn],son[maxn],top[maxn]; 29 int id[maxn]; 30 bool vis[maxn]; 31 int n; 32 ull add[maxn<<2],mul[maxn<<2],sum[maxn<<2]; 33 34 void dfs1(int d,int deep) 35 { 36 vector<int>::iterator j; 37 int dd; 38 vis[d]=1; 39 siz[d]=1; 40 dep[d]=deep; 41 son[d]=0; 42 for (j=e[d].begin();j!=e[d].end();j++) 43 { 44 dd=*j; 45 if (!vis[dd]) 46 { 47 fa[dd]=d; 48 dfs1(dd,deep+1); 49 siz[d]+=siz[dd]; 50 if (siz[dd]>siz[son[d]]) 51 son[d]=dd; 52 } 53 } 54 } 55 56 void dfs2(int d,int topd) 57 { 58 vector<int>::iterator j; 59 int dd; 60 id[d]=++num; 61 top[d]=topd; 62 if (son[d]!=0) 63 { 64 dfs2(son[d],topd); 65 for (j=e[d].begin();j!=e[d].end();j++) 66 { 67 dd=*j; 68 if (fa[d]!=dd && son[d]!=dd) 69 dfs2(dd,dd); 70 } 71 } 72 } 73 74 void build(int index,int l,int r) 75 { 76 add[index]=0; 77 mul[index]=1; 78 sum[index]=0; 79 if (l!=r) 80 { 81 int m=(l+r)>>1; 82 build(index<<1,l,m); 83 build(index<<1|1,m+1,r); 84 } 85 } 86 87 void push_down(int index,int len) 88 { 89 ///(xx*a+b)*c+d 90 add[index<<1]=add[index<<1]*mul[index]+add[index]; 91 add[index<<1|1]=add[index<<1|1]*mul[index]+add[index]; 92 93 mul[index<<1]=mul[index<<1]*mul[index]; 94 mul[index<<1|1]=mul[index<<1|1]*mul[index]; 95 96 sum[index<<1]=sum[index<<1]*mul[index]+add[index]*((len+1)>>1); /// 97 sum[index<<1|1]=sum[index<<1|1]*mul[index]+add[index]*(len>>1); 98 99 add[index]=0; 100 mul[index]=1; 101 } 102 103 void update_add(int index,int l,int r,int x,int y,ull k) 104 { 105 if (x<=l && r<=y) 106 { 107 sum[index]+=k*(r-l+1); 108 add[index]+=k; 109 return; 110 } 111 if (add[index]!=0 || mul[index]!=1) 112 push_down(index,r-l+1); 113 int m=(l+r)>>1; 114 if (x<=m) 115 update_add(index<<1,l,m,x,y,k); 116 if (m<y) 117 update_add(index<<1|1,m+1,r,x,y,k); 118 sum[index]=sum[index<<1]+sum[index<<1|1]; /// 119 } 120 121 void update_mul(int index,int l,int r,int x,int y,ull k) 122 { 123 if (x<=l && r<=y) 124 { 125 sum[index]*=k; 126 add[index]*=k; 127 mul[index]*=k; 128 return; 129 } 130 if (add[index]!=0 || mul[index]!=1) 131 push_down(index,r-l+1); 132 int m=(l+r)>>1; 133 if (x<=m) 134 update_mul(index<<1,l,m,x,y,k); 135 if (m<y) 136 update_mul(index<<1|1,m+1,r,x,y,k); 137 sum[index]=sum[index<<1]+sum[index<<1|1]; 138 } 139 140 ull query(int index,int l,int r,int x,int y) 141 { 142 if (x<=l && r<=y) 143 return sum[index]; 144 if (x>r || y<l) 145 return 0; 146 if (add[index]!=0 || mul[index]!=1) 147 push_down(index,r-l+1); 148 int m=(l+r)>>1; 149 return query(index<<1,l,m,x,y)+query(index<<1|1,m+1,r,x,y); 150 } 151 152 void work1(int x,int y,ull k) 153 { 154 while (top[x]!=top[y]) 155 { 156 if (dep[top[x]]<dep[top[y]]) 157 swap(x,y); 158 update_mul(1,1,n,id[top[x]],id[x],k); 159 x=fa[top[x]]; 160 } 161 if (dep[x]<dep[y]) 162 swap(x,y); 163 update_mul(1,1,n,id[y],id[x],k); 164 } 165 166 void work2(int x,int y,ull k) 167 { 168 while (top[x]!=top[y]) 169 { 170 if (dep[top[x]]<dep[top[y]]) 171 swap(x,y); 172 update_add(1,1,n,id[top[x]],id[x],k); 173 x=fa[top[x]]; 174 } 175 if (dep[x]<dep[y]) 176 swap(x,y); 177 update_add(1,1,n,id[y],id[x],k); 178 } 179 180 void work3(int x,int y) 181 { 182 while (top[x]!=top[y]) 183 { 184 if (dep[top[x]]<dep[top[y]]) 185 swap(x,y); 186 update_mul(1,1,n,id[top[x]],id[x],-1); 187 update_add(1,1,n,id[top[x]],id[x],-1); 188 x=fa[top[x]]; 189 } 190 if (dep[x]<dep[y]) 191 swap(x,y); 192 update_mul(1,1,n,id[y],id[x],-1); 193 update_add(1,1,n,id[y],id[x],-1); 194 } 195 196 ull work4(int x,int y) 197 { 198 ull tot=0; 199 while (top[x]!=top[y]) 200 { 201 if (dep[top[x]]<dep[top[y]]) 202 swap(x,y); 203 tot+=query(1,1,n,id[top[x]],id[x]); 204 x=fa[top[x]]; 205 } 206 if (dep[x]<dep[y]) 207 swap(x,y); 208 tot+=query(1,1,n,id[y],id[x]); 209 return tot; 210 } 211 212 int main() 213 { 214 int i,a,u,v,q,mode; 215 ull x; 216 while (~scanf("%d",&n)) 217 { 218 for (i=1;i<=n;i++) 219 e[i].clear(); 220 memset(vis,0,sizeof(vis)); 221 222 for (i=2;i<=n;i++) 223 { 224 scanf("%d",&a); 225 e[a].push_back(i); 226 } 227 dfs1(1,0); 228 num=0; 229 dfs2(1,1); 230 231 build(1,1,n); 232 233 scanf("%d",&q); 234 while (q--) 235 { 236 scanf("%d",&mode); 237 if (mode==1) 238 { 239 scanf("%d%d%llu",&u,&v,&x); 240 work1(u,v,x); 241 } 242 else if (mode==2) 243 { 244 scanf("%d%d%llu",&u,&v,&x); 245 work2(u,v,x); 246 } 247 else if (mode==3) 248 { 249 scanf("%d%d",&u,&v); 250 work3(u,v); 251 } 252 else 253 { 254 scanf("%d%d",&u,&v); 255 printf("%llu\n",work4(u,v)); 256 } 257 } 258 } 259 return 0; 260 } 261 /* 262 7 263 1 1 1 2 2 4 264 5 265 2 5 6 1 266 1 1 6 2 267 4 5 6 268 3 5 2 269 4 2 2 270 2 271 1 272 4 273 3 1 2 274 4 1 2 275 3 1 1 276 4 1 1 277 7 278 1 1 1 2 2 4 279 5 280 2 5 6 1 281 1 1 6 2 282 4 5 6 283 3 5 2 284 4 2 2 285 2 286 1 287 4 288 3 1 2 289 4 1 2 290 3 1 1 291 4 1 1 292 293 11 294 1 1 2 2 2 3 3 8 9 9 295 10 296 2 4 10 3 297 4 1 3 298 4 6 11 299 300 */
F. Modular Production Line
G. Give Candies
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e5+10; 25 26 char s[maxn]; 27 int a[maxn]; 28 29 int main() 30 { 31 int t,len,i; 32 ll x,y,z; 33 scanf("%d",&t); 34 while (t--) 35 { 36 scanf("%s",s); 37 len=strlen(s); 38 for (i=1;i<=len;i++) 39 a[i]=s[len-i]-48; 40 x=0; 41 for (i=len;i>=1;i--) 42 x=(x*10+a[i])%(mod-1); 43 x=(x-1+mod-1)%(mod-1); 44 y=2; 45 z=1; 46 while (x) 47 { 48 if (x & 1) 49 z=z*y%mod; 50 x>>=1; 51 y=y*y%mod; 52 } 53 printf("%lld\n",z); 54 } 55 return 0; 56 }
H. String and Times
I. Save the Room
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e2+10; 25 26 27 int main() 28 { 29 int x,y,z; 30 while (~scanf("%d%d%d",&x,&y,&z)) 31 { 32 if (x%2==1 && y%2==1 && z%2==1) 33 printf("No\n"); 34 else 35 printf("Yes\n"); 36 } 37 return 0; 38 }
J. Participate in E-sports
1. 不同方法时间上的比较 二分和另外一种方法 (l=(l+n/l)/2 )
其实还有倍增2^k(是否加)-> 2^(k-1)(是否加)-> 2^(k-2)(是否加)… 用加法代替二分的除法,应该会快一点。。。
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e5+10; 25 26 27 int main() 28 { 29 ll n=123456789; 30 ll l,r,m,v; 31 int x=0,y=0; 32 bool vis; 33 34 r=n; 35 while (1) 36 { 37 x++; 38 if (r*r==n) 39 { 40 vis=1; 41 break; 42 } 43 l=n/r; 44 if (l==r) 45 { 46 vis=0; 47 break; 48 } 49 r=(l+r)>>1; 50 } 51 52 l=1; r=n; 53 while (1) 54 { 55 y++; 56 m=(l+r)>>1; 57 v=m*m; 58 if (v==n) 59 { 60 vis=1; 61 break; 62 } 63 if (l==r) 64 break; 65 if (v<n) 66 l=m+1; 67 else 68 r=m-1; 69 } 70 71 printf("%d %d",x,y); 72 return 0; 73 } 74 75 /* 76 100 77 10 13 78 79 123456789 80 17 27 81 */
2.n*(n+1)/2 的找规律
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-10 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e5+10; 25 26 27 int main() 28 { 29 ll i; 30 double v; 31 for (i=1;i<=100000000;i++) 32 { 33 v=sqrt(i*(i+1)/2); 34 if (fabs(v-(ll)v)<minv) 35 printf("%lld\n",i); 36 } 37 return 0; 38 }
前一半:二分
后一半:找规律,打表。记录index每一个长度(二进制)都有哪些值
1 import java.math.BigInteger; 2 import java.util.Scanner; 3 4 public class Main { 5 public static void main(String[] args) { 6 boolean vis1,vis2; 7 Scanner in=new Scanner(System.in); 8 BigInteger b2=BigInteger.valueOf(2); 9 BigInteger b1=BigInteger.valueOf(1); 10 BigInteger b0=BigInteger.valueOf(0); 11 BigInteger []f=new BigInteger[1000]; 12 int [][]num=new int[1000][5]; 13 String s100=new String(); 14 BigInteger b100; 15 16 int i,j,k,len,q,v; 17 BigInteger n,l,r,m; 18 19 s100=s100+"1"; 20 for (i=1;i<=100;i++) 21 s100=s100+"0"; 22 b100=new BigInteger(s100); 23 24 ///100位以内就可以,因为还要平方 25 f[1]=BigInteger.valueOf(1); 26 f[2]=BigInteger.valueOf(7); 27 i=3; 28 while (true) 29 { 30 f[i]=f[i-1].multiply(BigInteger.valueOf(6)).subtract(f[i-2]); 31 if (f[i].compareTo(b100)>0) 32 break; 33 i++; 34 } 35 36 for (j=1;j<=i-1;j++) 37 { 38 f[j]=f[j].multiply(f[j]).add(b1); 39 len=f[j].bitLength(); 40 num[len][0]++; 41 num[len][num[len][0]]=j; 42 } 43 44 f[i]=BigInteger.valueOf(1); //index=1 45 len=f[i].bitLength(); 46 num[len][0]++; 47 num[len][num[len][0]]=i; 48 49 k=i+1; 50 f[i+1]=BigInteger.valueOf(3); 51 f[i+2]=BigInteger.valueOf(17); 52 i+=3; 53 54 while (true) 55 { 56 f[i]=f[i-1].multiply(BigInteger.valueOf(6)).subtract(f[i-2]); 57 if (f[i].compareTo(b100)>0) 58 break; 59 i++; 60 } 61 62 for (j=k;j<=i-1;j++) 63 { 64 f[j]=f[j].multiply(f[j]); 65 len=f[j].bitLength(); 66 num[len][0]++; 67 num[len][num[len][0]]=j; 68 } 69 70 q=in.nextInt(); 71 while (q-->0) 72 { 73 n=in.nextBigInteger(); 74 75 vis1=false; 76 l=b1; r=n; 77 while (l.compareTo(r)<=0) 78 { 79 m=l.add(r).divide(b2); 80 v=m.multiply(m).compareTo(n); 81 if (v==0) 82 { 83 vis1=true; 84 break; 85 } 86 if (v<0) 87 l=m.add(b1); 88 else 89 r=m.subtract(b1); 90 } 91 92 vis2=false; 93 len=n.bitLength(); 94 95 for (i=1;i<=num[len][0];i++) 96 if (n.equals(f[num[len][i]])==true) 97 { 98 vis2=true; 99 break; 100 } 101 102 if (vis1 && vis2) 103 System.out.println("Arena of Valor"); 104 else if (vis1 && !vis2) 105 System.out.println("Hearth Stone"); 106 else if (!vis1 && vis2) 107 System.out.println("Clash Royale"); 108 else 109 System.out.println("League of Legends"); 110 } 111 } 112 } 113 /* 114 272796309905283809401 115 116 2391711738256 117 118 */
P.S:
队友求模小质数。过了~
K. Transport Ship
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e4+10; 25 26 ll er[30],value=1e4; 27 ll f[maxn]; 28 29 int main() 30 { 31 int t,n,q,i,j,v,c; 32 scanf("%d",&t); 33 er[0]=1; 34 for (i=1;i<=20;i++) 35 er[i]=er[i-1]<<1; 36 while (t--) 37 { 38 f[0]=1; 39 for (i=1;i<=value;i++) 40 f[i]=0; 41 scanf("%d%d",&n,&q); 42 while (n--) 43 { 44 scanf("%d%d",&v,&c); 45 for (i=0;i<c;i++) 46 for (j=value;j>=er[i]*v;j--) 47 f[j]=(f[j]+f[j-er[i]*v])%mod; 48 } 49 while (q--) 50 { 51 scanf("%d",&i); 52 printf("%lld\n",f[i]); 53 } 54 } 55 return 0; 56 }
L. Poor God Water
1 #include <cstdio> 2 #include <cstdlib> 3 #include <cmath> 4 #include <cstring> 5 #include <time.h> 6 #include <string> 7 #include <set> 8 #include <map> 9 #include <list> 10 #include <stack> 11 #include <queue> 12 #include <vector> 13 #include <bitset> 14 #include <ext/rope> 15 #include <algorithm> 16 #include <iostream> 17 using namespace std; 18 #define ll long long 19 #define minv 1e-6 20 #define inf 1e9 21 #define pi 3.1415926536 22 #define nl 2.7182818284 23 const ll mod=1e9+7;//998244353 24 const int maxn=1e2+10; 25 26 ll a[9][9],b[9][9],c[9][9]; 27 28 void init() 29 { 30 31 int i,j; 32 for (i=0;i<9;i++) 33 for (j=0;j<9;j++) 34 a[i][j]=0; 35 36 a[2][0]=1; 37 a[1][0]=1; 38 a[3][1]=1; 39 a[4][1]=1; 40 a[5][1]=1; 41 a[6][2]=1; 42 a[8][2]=1; 43 a[0][3]=1; 44 a[1][3]=1; 45 a[2][3]=1; 46 a[3][4]=1; 47 a[5][4]=1; 48 a[7][5]=1; 49 a[8][5]=1; 50 a[0][6]=1; 51 a[1][6]=1; 52 a[3][7]=1; 53 a[4][7]=1; 54 a[6][8]=1; 55 a[7][8]=1; 56 57 58 for (i=0;i<9;i++) 59 for (j=0;j<9;j++) 60 b[i][j]=0; 61 for (i=0;i<9;i++) 62 b[i][i]=1; 63 for (i=0;i<9;i++) 64 for (j=0;j<9;j++) 65 c[i][j]=0; 66 } 67 68 int main() 69 { 70 ///%mod 71 ///<3 72 ll n,r; 73 int t,i,j,k; 74 75 // init(); 76 // for (i=0;i<9;i++) 77 // for (j=0;j<9;j++) 78 // for (k=0;k<9;k++) 79 // c[i][j]=(c[i][j]+a[i][k]*a[k][j])%mod; 80 // r=0; 81 // for (i=0;i<9;i++) 82 // for (j=0;j<9;j++) 83 // r=(r+c[i][j])%mod; 84 // 85 // printf("%d\n",r); 86 // return 0; 87 88 ///b:danwei result 89 ///a:*** 90 91 92 scanf("%d",&t); 93 while (t--) 94 { 95 init(); 96 scanf("%lld",&n); 97 if (n==1) 98 printf("3\n"); 99 else 100 { 101 n-=2; 102 103 while (n) 104 { 105 if (n & 1) 106 { 107 for (i=0;i<9;i++) 108 for (j=0;j<9;j++) 109 { 110 c[i][j]=b[i][j]; 111 b[i][j]=0; 112 } 113 for (i=0;i<9;i++) 114 for (j=0;j<9;j++) 115 for (k=0;k<9;k++) 116 b[i][j]=(b[i][j]+a[i][k]*c[k][j])%mod; 117 } 118 119 for (i=0;i<9;i++) 120 for (j=0;j<9;j++) 121 { 122 c[i][j]=a[i][j]; 123 a[i][j]=0; 124 } 125 for (i=0;i<9;i++) 126 for (j=0;j<9;j++) 127 for (k=0;k<9;k++) 128 a[i][j]=(a[i][j]+c[i][k]*c[k][j])%mod; 129 n>>=1; 130 } 131 132 r=0; 133 for (i=0;i<9;i++) 134 for (j=0;j<9;j++) 135 r=(r+b[i][j])%mod; 136 printf("%lld\n",r); 137 } 138 } 139 return 0; 140 } 141 /* 142 3 143 9 144 20 145 46 146 106 147 244 148 560 149 1286 150 2956 151 6794 152 15610 153 35866 154 82416 155 189384 156 435170 157 */