This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
typedef struct{
long long M[9][9];
} mat;
mat A;
long long X[9][9]={1,0,0,0,1,0,1,1,0, 1,0,0,0,0,0,1,1,0, 1,0,0,0,1,0,0,1,0, 1,0,0,0,1,0,1,0,0, 0,1,0,0,0,0,0,0,1, 0,1,0,0,0,0,0,0,0, 0,0,1,0,0,0,0,0,0, 0,0,0,1,0,1,0,0,0, 0,0,0,1,0,0,0,0,0};
mat matmul(mat x, mat y){
mat ret;
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
ret.M[i][j]=0LL;
}
}
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
for(int k=0;k<9;k++){
ret.M[i][k]=(ret.M[i][k]+x.M[i][j]*y.M[j][k])%1000000007LL;
}
}
}
return ret;
}
mat matpow(mat x, int p){
if(p==1) return x;
mat h=matpow(x,p/2);
if(p&1) return matmul(matmul(h,h),x);
return matmul(h,h);
}
mat ans;
long long pans=0LL;
int main(){
int N;
scanf("%d",&N);
for(int i=0;i<9;i++){
for(int j=0;j<9;j++){
A.M[i][j]=X[i][j];
}
}
ans=matpow(A,N-2);
for(int i=0;i<9;i++) pans=(pans+ans.M[i][0])%1000000007LL;
printf("%lld",pans);
}
Compilation message (stderr)
cross.cpp: In function 'int main()':
cross.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&N);
~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |