-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#define MOD 1000000007 | ||
using namespace std; | ||
using Matrix = vector<vector<long long>>; | ||
|
||
Matrix matmul(Matrix a, Matrix b) { | ||
Matrix c(2, vector<long long>(2)); | ||
for (int i=0; i<2; i++) for (int j=0; j<2; j++) for (int k=0; k<2; k++) { | ||
c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD; | ||
} | ||
return c; | ||
} | ||
|
||
Matrix matpow(Matrix base, long long exp) { | ||
Matrix ret(2, vector<long long>(2, 0)); | ||
for (int i=0; i<2; i++) ret[i][i] = 1; | ||
while (exp) { | ||
if (exp & 1) ret = matmul(ret, base); | ||
base = matmul(base, base); | ||
exp >>= 1; | ||
} | ||
return ret; | ||
} | ||
|
||
void solve(void) { | ||
long long n; cin >> n; | ||
|
||
cout << (matpow({{1, 1}, {1, 0}}, n)[0][1] * matpow({{1, 1}, {1, 0}}, n+1)[0][1]) % MOD; | ||
} | ||
|
||
int main(void) { | ||
ios::sync_with_stdio(false); | ||
cin.tie(nullptr); | ||
|
||
solve(); | ||
return 0; | ||
} |