2016
Given a 2×2 matrix
Special Note: The problem is intended to be easy. Feel free to think why the problem is called 2016
if you either:
- find it hard to solve;
- or, solved all the other problems easily.
Input
The input contains at most 40 sets. For each set:
The first line contains an integer n ( 1≤n<10100000 ).
The second line contains 2 integers a11,a12 .
The third line contains 2 integers a21,a22 .
( 0≤aij<7 , (a11a22−a12a21) is not a multiple of 7 )
Output
For each set, a 2×2 matrix denotes the remainder of An after division by 7 .
Sample Input
2 1 1 1 2 2016 1 1 1 2
Sample Output
2 3 3 5 1 00 1
ACcode:
#include <bits/stdc++.h> #define maxn 100010 #define mod 7 using namespace std; struct N{ int mat[2][2]; }my; inline N mul(N a,N b){ N ret; for(int i=0;i<2;++i) for(int j=0;j<2;++j){ ret.mat[i][j]=0; for(int k=0;k<2;++k) ret.mat[i][j]=(ret.mat[i][j]+a.mat[i][k]*b.mat[k][j]%mod)%7; } return ret; } inline N pow_M(N a,int n){ N ret; memset(ret.mat,0,sizeof(ret.mat)); for(int i=0;i<2;++i)ret.mat[i][i]=1; N tmp=a; while(n){ if(n&1)ret=mul(ret,tmp); tmp=mul(tmp,tmp); n>>=1; } return ret; } char nn[maxn]; int main(){ while(~scanf("%s",nn)){ int len=strlen(nn); int n=0; for(int i=0;i<len;++i) n=(n*10+nn[i]-'0')%2016; scanf("%d%d%d%d",&my.mat[0][0],&my.mat[0][1],&my.mat[1][0],&my.mat[1][1]); N tmp=pow_M(my,n); printf("%d %d\n%d %d\n",tmp.mat[0][0]%mod,tmp.mat[0][1]%mod,tmp.mat[1][0]%mod,tmp.mat[1][1]%mod); } return 0; }