// #ifndef ONLINE_JUDGE // #define _GLIBCXX_DEBUG//[]で配列外参照をするとエラーにしてくれる。上下のやつがないとTLEになるので注意 ABC311Eのサンプル4みたいなデバック中のTLEは防げないので注意 // #endif #include using namespace std; // #include // using namespace atcoder; template using vc = vector;//prioriy_queueに必要なのでここにこれ書いてます template using vv = vc>; //-------------1.型系--------------- using ll = long long; ll INF = 2e18; // #include //インストール的なのをしてないとできないので注意 // namespace multip = boost::multiprecision; // //using lll = multip::cpp_int;//無制限を使いたいときはこっちを使う // using lll = multip::int128_t; using ld = long double; using bl = bool; // using mint = modint998244353; //using mint = modint1000000007; //using mint = modint;//使うときはコメントアウトを外す //mint::set_mod(m);//使うときはコメントアウトを外す template using pq = priority_queue>;//大きい順 template using pq_g = priority_queue, greater>;//小さい順 //----------------------------------- //-------------2.配列系-------------- using vl = vc; using vvl = vv; using vvvl = vv; using vvvvl = vv; using vs = vc; using vvs = vv; using vb = vc; using vvb = vv; using vvvb = vv; using vld = vc; using vvld = vv; using vvvld = vv; using pii = pair; using pll = pair; // using vmint = vc; using vvmint = vv; using vvvmint = vv; //配列外参照対策のやつは一番上の行にあります #define rep(i,n) for(ll i = 0; i < (n); ++i)//↓でrepを使うので書いてます templateistream& operator>>(istream& i, vc& v) { rep(j, size(v))i >> v[j]; return i; } using ar2 = array; //---------------------------------- //--------3.コード短縮化とか--------- #define rep(i,n) for(ll i = 0; i < (n); ++i) #define rrep(i,n) for(ll i = 1; i <= (n); ++i) #define drep(i,n) for(ll i = (n)-1; i >= 0; --i) #define nfor(i,s,n) for(ll i=s;i=n;i--)//s-1スタートでnまで落ちる #define nall(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define chmax(x,y) x = max(x,y) #define chmin(x,y) x = min(x,y) #define pb push_back #define eb emplace_back #define em emplace #define pob pop_back #define YES cout<<"Yes"<T tousa_sum1(T l, T d, T r) {//初項,公差,末項 で総和を求める T wide = (r - l) / d + 1; return (l + r) * wide / 2; } templateT tousa_sum2(T a, T d, T n) {//初項,交差,項数 で総和を求める return (a * 2 + d * (n - 1)) * n / 2; } ll kousa_kousuu(ll l, ll r, ll d) {//初項,末項,交差 で等差数列の項数を求める return (r - l) / d + 1; } // mint touhi_sum(mint a, mint r, ll n) {//初項,公比,項数で等比数列の総和を求める // if (r == 1) { // return a * n; // } // mint bunsi = a * (r.pow(n) - mint(1)); // mint bunbo = r - 1; // return bunsi / bunbo; // } ll nc2(ll x) { return x * (x - 1) / 2; } ll nc3(ll x) { return x * (x - 1) * (x - 2) / 6; } //---------------------------------------------- //-----------6.デバックや出力系------------------ void print(ld x) { printf("%.20Lf\n", x); } void mukou_debug(vvl to, bool yukou) {//GRAPH × GRAPH用の無向グラフを出力する ll n = size(to); ll cnt = 0;//辺の本数 vc>v; rep(i, n)for (ll t : to[i]) if (i < t || yukou)cnt++, v.eb(i + 1, t + 1);//有向グラフなら全部OK、違うなら無向なのでfにしてる cout << n << ' ' << cnt << endl; for (auto [f, t] : v)cout << f << ' ' << t << endl; } #define vc_cout(v){ll n = size(v);rep(i,n)cout<> 1); } return res; } int main(){ ll n, m; cin >> n >> m; vvl a = {{1, 1}, {1, 0}}; vvl aa = matrixPow(a, n-2, m); vvl init = {{1}, {0}}; vvl ans = matrixMulti(aa, init, m); cout << ans[0][0] << endl; return 0; }