// #define _GLIBCXX_DEBUG #include using namespace std; using ll = long long; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template class Matrix { private: vector> A; ll mod; public: Matrix(){} Matrix(size_t n): A(n, vector(n, T{})){ assert(n > 0); } Matrix(size_t h, size_t w): A(h, vector(w, T{})){ assert(h > 0 && w > 0); } Matrix(size_t h, size_t w, ll m): A(h, vector(w, T{})), mod(m) { assert(h > 0 && w > 0); } size_t getHeight() const { return A.size(); } size_t getWidth() const { assert(!A.empty()); return A[0].size(); } // when you read the item inline const vector &operator[](size_t k) const { return A.at(k); } // when you assign the item inline vector &operator[](size_t k){ return A.at(k); } // Matrix I = Matrix::I(n); static Matrix I(size_t n){ Matrix mat_I(n); for(size_t i=0; i> C(h, vector(w, 0)); for(size_t i=0; i= 0); Matrix B = Matrix::I(h); while(k > 0){ if(k & 1) B *= (*this); (*this) *= (*this); k >>= 1; } A.swap(B.A); return (*this); } Matrix operator+(const Matrix &B) const { return (Matrix(*this) += B); } Matrix operator-(const Matrix &B) const { return (Matrix(*this) -= B); } Matrix operator*(const Matrix &B) const { return (Matrix(*this) *= B); } Matrix operator^(const long long k) const { return (Matrix(*this) ^= k); } friend ostream &operator<<(ostream &os, const Matrix &p){ size_t h = p.getHeight(); size_t w = p.getWidth(); for(size_t i=0; i> n >> m; Matrix F(2, 1, m); Matrix M(2, 2, m); F[0][0] = 0; F[1][0] = 1; M[0][0] = 1; M[0][1] = 1; M[1][0] = 1; M[1][1] = 0; M ^= (n-1); Matrix ans = M * F; cout << ans[0][0] << endl; }