Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Moca Andrei - 100p
- #include <bits/stdc++.h>
- using namespace std;
- const int MOD(777013);
- struct matrix {
- int64_t a, b, c, d;
- };
- inline matrix Multiply(matrix const& x, matrix const& y) {
- matrix res;
- res.a = (x.a * y.a) % MOD + (x.b * y.c) % MOD;
- res.b = (x.a * y.b) % MOD + (x.b * y.d) % MOD;
- res.c = (x.c * y.a) % MOD + (x.d * y.c) % MOD;
- res.d = (x.c * y.b) % MOD + (x.d * y.d) % MOD;
- return res;
- }
- inline matrix Pow(matrix const& x, int const& k) {
- if (k == 0) return {0, 0, 0, 0};
- if (k == 1) return {0, 1, 1, 1};
- if (k == 2) return {1, 1, 1, 2};
- matrix res = Pow(x, k / 2);
- if (k % 2 == 0)
- return Multiply(res, res);
- else {
- matrix y = Multiply(res, res);
- return Multiply(y, x);
- }
- }
- inline int Fib(int const& k) {
- return Pow({0, 1, 1, 1}, k).b;
- }
- int n;
- int main() {
- cin >> n;
- cout << (Fib(n + 2) + MOD - 1) % MOD;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement