#include using namespace std; #include using namespace atcoder; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep1(i, n) for (int i = 1; i < (int)(n+1); i++) #define all(x) (x).begin(), (x).end() using mint = modint1000000007; //using mint = modint998244353; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair P; typedef pair PL; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; typedef vector vd; typedef vector vvd; const int INF = 1<<30; const long long INFL = (ll)1<<60; const double PI = 3.14159265358979; //行列積 a*b (mod mod) の計算 vvl mat_mul(vvl &a, vvl &b, int mod){ int m = a.size(), n = b[0].size(), l = a[0].size(); vvl c(m, vl(n, 0)); rep(i, m){ rep(k, l){ rep(j, n){ c[i][j] += a[i][k] * b[k][j]; c[i][j] %= mod; } } } return c; } //行列累乗 a^n (mod mod) の計算 計算量:O(size^3 * logn) vvl mat_pow(vvl &a, int n, int mod){ int size = a.size(); vvl ret(size, vl(size, 0)); vvl b = a; rep(i, size){ rep(j, size){ if(i == j)ret[i][j] = 1; } } int k = 1; while((1<> n >> m; vvl a = {{1, 1}, {1, 0}}; vvl tmp = mat_pow(a, n-1, m); cout << tmp[1][0] << endl; return 0; }