#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 long long ull; typedef pair P; typedef pair PL; typedef vector vi; typedef vector vvi; typedef vector vl; typedef vector vvl; const int INF = 1<<30; const long long INFL = (ll)1<<60; const double PI = 3.14159265358979; 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; } vvl mat_pow(vvl &a, int n, int mod){ int size = a.size(); vvl ret(size, vl(size, 0)); vvl b(size, vl(size)); rep(i, size){ rep(j, size){ if(i == j)ret[i][j] = 1; b[i][j] = a[i][j]; } } int k = 1; while((1<> n >> m; vvl a(2, vl(2, 1)); a[1][1] = 0; vvl a_pow = mat_pow(a, n-1, m); cout << a_pow[1][0] << endl; return 0; }