25uint64_t
fibo(uint64_t n, uint64_t mod) {
26 std::vector<uint64_t> result(2, 0);
27 std::vector<std::vector<uint64_t>> transition(2,
28 std::vector<uint64_t>(2, 0));
29 std::vector<std::vector<uint64_t>> Identity(2, std::vector<uint64_t>(2, 0));
31 result[0] = 1, result[1] = 1;
38 transition[1][0] = transition[1][1] = transition[0][1] = 1;
42 std::vector<std::vector<uint64_t>> res(2,
43 std::vector<uint64_t>(2, 0));
44 for (
int i = 0; i < 2; i++) {
45 for (
int j = 0; j < 2; j++) {
46 for (
int k = 0; k < 2; k++) {
49 ((Identity[i][k] % mod * transition[k][j] % mod)) %
55 for (
int i = 0; i < 2; i++) {
56 for (
int j = 0; j < 2; j++) {
57 Identity[i][j] = res[i][j];
62 std::vector<std::vector<uint64_t>> res1(
63 2, std::vector<uint64_t>(2, 0));
64 for (
int i = 0; i < 2; i++) {
65 for (
int j = 0; j < 2; j++) {
66 for (
int k = 0; k < 2; k++) {
68 (res1[i][j] % mod + ((transition[i][k] % mod *
69 transition[k][j] % mod)) %
75 for (
int i = 0; i < 2; i++) {
76 for (
int j = 0; j < 2; j++) {
77 transition[i][j] = res1[i][j];
83 return ((result[0] % mod * Identity[0][0] % mod) % mod +
84 (result[1] % mod * Identity[1][0] % mod) % mod) %