Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define ll long long
- using namespace std;
- const ll Mod = 1e9 + 7;
- const ll Nax = 110;
- const ll Inf = 4e18;
- ll N , Start , End;
- ///For Easy Code
- #define rep(i,v) for(ll i=0;i<v.size();++i)
- typedef vector < ll > Row;
- typedef vector < Row > Matrix;
- ///Zero Matrix
- Matrix Zero(ll n,ll m)
- {
- return Matrix( n , Row(m,0) );
- }
- ///Identity Matrix
- Matrix Identity(ll n)
- {
- Matrix Res = Zero(n,n);
- rep(i,Res) Res[i][i] = 1;
- return Res;
- }
- ///Matrix Multiplication
- Matrix Muliply(const Matrix &a,const Matrix &b)
- {
- Matrix Res=Zero( a.size() , b[0].size() );
- rep(i,a) rep(k,a[0]) if(a[i][k])
- rep(j,b[0])
- Res[i][j] = ( Res[i][j] + a[i][k] * b[k][j] )%Mod;
- return Res;
- }
- ///Matrix Power
- Matrix Power(const Matrix &a,ll k)
- {
- if(k==0) return Identity( a.size() );
- if(k&1) return Muliply( a , Power(a,k-1) );
- return Power( Muliply(a,a) , k>>1LL );
- }
- int main()
- {
- Matrix Adj = Zero(9, 9);
- ll n; cin >> n;
- Adj[0][0] = Adj[0][1] = Adj[0][2] = 1;
- Adj[1][3] = Adj[1][4] = Adj[1][5] = 1;
- Adj[2][6] = Adj[2][7] = Adj[2][8] = 1;
- Adj[3][0] = 1;
- Adj[4][3] = Adj[4][4] = 1;
- Adj[5][6] = Adj[5][7] = Adj[5][8] = 1;
- Adj[6][0] = 1;
- Adj[7][3] = 1;
- Adj[8][6] = Adj[8][7] = Adj[8][8] = 1;
- Adj = Power(Adj, n - 2);
- ll Ans = 0;
- for (int i = 0; i < 9; i++)
- for (int j = 0; j < 9; j++)
- Ans = (Ans%Mod + Adj[i][j]%Mod)%Mod;
- cout << Ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement