Advertisement
a53

NumarDeSubmultimi1

a53
Jan 8th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. /// Moca Andrei - 100p
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. const int MOD(777013);
  5. struct matrix {
  6. int64_t a, b, c, d;
  7. };
  8. inline matrix Multiply(matrix const& x, matrix const& y) {
  9. matrix res;
  10. res.a = (x.a * y.a) % MOD + (x.b * y.c) % MOD;
  11. res.b = (x.a * y.b) % MOD + (x.b * y.d) % MOD;
  12. res.c = (x.c * y.a) % MOD + (x.d * y.c) % MOD;
  13. res.d = (x.c * y.b) % MOD + (x.d * y.d) % MOD;
  14. return res;
  15. }
  16. inline matrix Pow(matrix const& x, int const& k) {
  17. if (k == 0) return {0, 0, 0, 0};
  18. if (k == 1) return {0, 1, 1, 1};
  19. if (k == 2) return {1, 1, 1, 2};
  20. matrix res = Pow(x, k / 2);
  21. if (k % 2 == 0)
  22. return Multiply(res, res);
  23. else {
  24. matrix y = Multiply(res, res);
  25. return Multiply(y, x);
  26. }
  27. }
  28. inline int Fib(int const& k) {
  29. return Pow({0, 1, 1, 1}, k).b;
  30. }
  31. int n;
  32. int main() {
  33. cin >> n;
  34. cout << (Fib(n + 2) + MOD - 1) % MOD;
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement