#include using namespace std; #define ll long long #define ull unsigned long long #ifdef ONLINE_JUDGE #define DPRINT(str) #else #define DPRINT(str) std::cout<<(#str)<< " = "<<(str)< " << (*i).second; \ } \ os << " }"; \ return os; \ } while (0) #define PRINT_SET(os, c) \ do { \ os << "( "; \ for (auto i = c.begin(); i != c.end(); i++) { \ if (i != c.begin()) { \ os << ", "; \ } \ os << *i; \ } \ os << " )"; \ return os; \ } while (0) template std::ostream& operator<<(std::ostream& os, const std::vector& c); template std::ostream& operator<<(std::ostream& os, const std::deque& c); template std::ostream& operator<<(std::ostream& os, const std::list& c); template std::ostream& operator<<(std::ostream& os, const std::forward_list& c); template std::ostream& operator<<(std::ostream& os, const std::map& c); template std::ostream& operator<<(std::ostream& os, const std::multimap& c); template std::ostream& operator<<(std::ostream& os, const std::unordered_map& c); template std::ostream& operator<<(std::ostream& os, const std::unordered_multimap& c); template std::ostream& operator<<(std::ostream& os, const std::set& c); template std::ostream& operator<<(std::ostream& os, const std::multiset& c); template std::ostream& operator<<(std::ostream& os, const std::unordered_set& c); template std::ostream& operator<<(std::ostream& os, const std::unordered_multiset& c); template std::ostream& operator<<(std::ostream& os, const std::pair& p); template std::ostream& operator<<(std::ostream& os, const std::tuple& t); template std::ostream& operator<<(std::ostream& os, std::priority_queue c); template std::ostream& operator<<(std::ostream& os, const std::vector& c) { PRINT(os, c); } template std::ostream& operator<<(std::ostream& os, const std::deque& c) { PRINT(os, c); } template std::ostream& operator<<(std::ostream& os, const std::list& c) { PRINT(os, c); } template std::ostream& operator<<(std::ostream& os, const std::forward_list& c) { PRINT(os, c); } template std::ostream& operator<<(std::ostream& os, const std::map& c) { PRINT_MAP(os, c); } template std::ostream& operator<<(std::ostream& os, const std::multimap& c) { PRINT_MAP(os, c); } template std::ostream& operator<<(std::ostream& os, const std::unordered_map& c) { PRINT_MAP(os, c); } template std::ostream& operator<<(std::ostream& os, const std::unordered_multimap& c) { PRINT_MAP(os, c); } template std::ostream& operator<<(std::ostream& os, const std::set& c) { PRINT_SET(os, c); } template std::ostream& operator<<(std::ostream& os, const std::multiset& c) { PRINT_SET(os, c); } template std::ostream& operator<<(std::ostream& os, const std::unordered_set& c) { PRINT_SET(os, c); } template std::ostream& operator<<(std::ostream& os, const std::unordered_multiset& c) { PRINT_SET(os, c); } template std::ostream& operator<<(std::ostream& os, const std::pair& p) { os << "< " << p.first << ", " << p.second << " >"; return os; } template void PRINT_PARAMS(std::ostream& os, const Head& head){ os< void PRINT_PARAMS(std::ostream& os, const Head& head, const Tail&... tail){ os< void PRINT_TUPLE_WITH_SEQUENCE( std::ostream& os, const T t, std::index_sequence){ PRINT_PARAMS(os, std::get(t)...); } template std::ostream& operator<<(std::ostream& os, const std::tuple& t){ os<<"< "; PRINT_TUPLE_WITH_SEQUENCE(os, t, std::make_index_sequence>::value>{}); os<<" >"; return os; } template std::ostream& operator<<(std::ostream& os, std::priority_queue c) { vector tmp; while(!c.empty()){ tmp.push_back(c.top()); c.pop(); } PRINT(os, tmp); } template void SCAN_PARAMS(std::istream& is, Head& head){ is>>head; } template void SCAN_PARAMS(std::istream& is, Head& head, Tail&... tail){ is>>head; SCAN_PARAMS(is, tail...); } template void SCAN_TUPLE_WITH_SEQUENCE( std::istream& is, T& t, std::index_sequence){ SCAN_PARAMS(is, std::get(t)...); } template std::istream& operator>>(std::istream& is, std::tuple& t); template std::istream& operator>>(std::istream& is, std::vector& c); template std::istream& operator>>(std::istream& is, std::pair& p); template std::istream& operator>>(std::istream& is, std::tuple& t){ SCAN_TUPLE_WITH_SEQUENCE(is, t, std::make_index_sequence>::valu\ e>{}); return is; } template std::istream& operator>>(std::istream& is, std::vector& c){ for(auto& e:c) is>>e; return is; } template std::istream& operator>>(std::istream& is, std::pair& p) { is >> p.first >> p.second; return is; } template std::pair operator+(const std::pair& l, const std::pair& r){ return {l.first+r.first, l.second+r.second}; } template std::pair operator-(const std::pair& l, const std::pair& r){ return {l.first-r.first, l.second-r.second}; } template std::pair operator*(const std::pair& l, const int n){ return {l.first*n, l.second*n}; } template std::pair operator/(const std::pair& l, const int n){ return {l.first/n, l.second/n}; } template inline T lsb(const T& n){ return n & (~n + 1); } unsigned long long int factorial(unsigned long long int n){ if(n<=1)return 1; return n*factorial(n-1); } unsigned long long int combination(unsigned long long int n, unsigned long long int r, vector>& v){ if(n-r> v(n+1,vector(r+1, 0)); return combination(n, r, v); } template T exponentiation(T n, T m, T mod = 0){ T ret = 1; for(T i = 0;(m>>i)>0;i++){ if((1<0)ret%=mod; } n=n*n; if(mod>0)n%=mod; } return ret; } template vector> matrix_multiply(const vector>& X, const vector>& Y, ll M) { vector> Z(X.size(), vector(Y[0].size())); for(int i = 0;i vector> matrix_pow(vector> A, ll n, ll M) { vector> B(A.size(), vector(A[0].size())); for(int i = 0;i0) { if (n & 1) B = matrix_multiply(B, A, M); A = matrix_multiply(A, A, M); n = n >> 1; } return B; } int main(void){ ll N,M; cin>>N>>M; N--; vector> A({{1, 1},{1,0}}); // DPRINT(A); A = matrix_pow(A, N, M); // DPRINT(A); cout<