#include using namespace std; #define VT(Type) vector typedef long long LI; typedef VT(LI) VI; typedef VT(VI) VVI; typedef VT(VVI) V3I; typedef VT(V3I) V4I; typedef long double LD; typedef VT(LD) VD; typedef VT(VD) VVD; typedef VT(bool) VB; typedef VT(VB) VVB; typedef VT(string) VS; typedef VT(VS) VVS; typedef pair PII; typedef VT(PII) VPII; typedef VT(VPII) VVPII; typedef pair PDD; typedef VT(PDD) VPDD; typedef VT(VPDD) VVPDD; typedef pair PSI; typedef VT(PSI) VPSI; typedef set
  • SI; typedef set SPII; typedef multiset
  • mSI; typedef VT(SI) VSI; typedef map MII; typedef map MPIII; typedef multimap mMII; typedef VT(MII) VMII; typedef map MSI; typedef multimap mMSI; typedef VT(MSI) VMSI; typedef queue
  • QI; typedef queue QPII; typedef priority_queue > PQPII; //優先順位付きqueue(昇順) #define PQD(Type) priority_queue #define PQU(Type) priority_queue > #define PQ(Type) priority_queue > #define REP(i, j, k) for(LI i = j; i < (LI)k; i++) #define RREP(i, k, j) for(LI i = j - 1; i >= (LI)k; i--) #define rep(i, j) REP(i, 0, j) #define rrep(i, j) RREP(i, 0, j) #define vrep(a, v) for(auto& a: v) #define vcrep(a, v) for(const auto& a: v) // 要素数 R の部分集合を bit全探索 #define brep(bit, N, R) for (LI bit = bits(R) - 1, x, y; bit < bits(N); x = bit & -bit, y = bit + x, bit = (((bit & ~y) / x) >> 1) | y) #define all(v) v.begin(), v.end() #define vsort(v) sort(all(v)); #define vsorto(v, o) sort(all(v), o); #define vsortr(v) vsorto(v, greater
  • ()) #define scan(Type, a) Type a; cin >> a; #define scan2(Type, a, b) scan(Type, a) scan(Type, b) #define scan3(Type, a, b, c) scan2(Type, a, b) scan(Type, c) #define scan4(Type, a, b, c, d) scan3(Type, a, b, c) scan(Type, d) #define iscan(a) scan(LI, a) #define iscan2(a, b) scan2(LI, a, b) #define iscan3(a, b, c) scan3(LI, a, b, c) #define iscan4(a, b, c, d) scan4(LI, a, b, c, d) #define iscand(a) iscan(a) a--; #define iscand2(a, b) iscand(a) iscand(b) #define iscand3(a, b, c) iscand2(a, b) iscand(c) #define iscand4(a, b, c, d) iscand3(a, b, c) iscand(d) #define sscan(a) scan(string, a); #define sscan2(a, b) scan(string, a, b); #define vscan(Type, A, N) VT(Type) A(N); rep(mci, N) cin >> A[mci]; #define vscan2(Type, A, B, N) VT(Type) A(N), B(N); rep(mci, N) cin >> A[mci] >> B[mci]; #define vscan3(Type, A, B, C, N) VT(Type) A(N), B(N), C(N); rep(mci, N) cin >> A[mci] >> B[mci] >> C[mci]; #define vscan4(Type, A, B, C, D, N) VT(Type) A(N), B(N), C(N), D(N); rep(mci, N) cin >> A[mci] >> B[mci] >> C[mci] >> D[mci]; #define vvscan(Type, A, H, W) VT(VT(Type)) A(H, VT(Type)(W)); rep(mch, H) rep(mcw, W) cin >> A[mch][mcw]; #define viscan(A, N) vscan(LI, A, N) #define viscan2(A, B, N) vscan2(LI, A, B, N) #define viscan3(A, B, C, N) vscan3(LI, A, B, C, N) #define viscan4(A, B, C, D, N) vscan4(LI, A, B, C, D, N) #define vviscan(A, H, W) vvscan(LI, A, H, W) #define viscand(A, N) viscan(A, N) rep(mci, N) A[mci]--; #define viscand2(A, B, N) viscan2(A, B, N) rep(mci, N) { A[mci]--; B[mci]--; } #define viscand3(A, B, C, N) viscan3(A, B, C, N) rep(mci, N) { A[mci]--; B[mci]--; C[mci]--; } #define viscand4(A, B, C, D, N) viscan4(A, B, C, D, N) rep(mci, N) { A[mci]--; B[mci]--; C[mci]--; D[mci]--; } #define vviscand(A, H, W) vviscan(A, H, W) rep(mch, H) rep(mcw, W) A[mch][mcw]--; #define vpiscan(A, N) VPII A(N); rep(mci, N) cin >> A[mci].first >> A[mci].second; #define vpiscand(A, N) vpiscan(A, N); rep(mci, N) { A[mci].first--; A[mci].second--; } #define vpdscan(A, N) VPDD A(N); rep(mci, N) cin >> A[mci].first >> A[mci].second; #define vsscan(S, N) vscan(string, S, N); #define giscand(G, N, E) VVI G(N); rep(mci, E) { iscand2(mca, mcb); G[mca].push_back(mcb); } #define gsscand(G, N, E) VVI G(N); rep(mci, E) { iscand2(mca, mcb); G[mca].push_back(mcb); G[mcb].push_back(mca); } #define bits(x) (1LL << x) #define inf(x) (x != INF ? x : -1) #define maxa(a, b) a = max(a, b); #define mina(a, b) a = min(a, b); #define mida(a, b, c) a = min(max(a, b), c); #define px front().first #define py front().second #define miman(v, a) (lower_bound(all(v), a) - v.begin()) #define ika(v, a) (upper_bound(all(v), a) - v.begin()) #define ijo(v, a) (v.end() - lower_bound(all(v), a)) #define yorio(v, a) (v.end() - upper_bound(all(v), a)) #define debug(x) cout << ">> " << #x << " = " << x << endl; #define el cout << endl; #define shown(a) cout << (a) << " "; #define shown2(a, b) cout << (a) << " " << (b) << " "; #define shown3(a, b, c) cout << (a) << " " << (b) << " " << (c) << " "; #define shown4(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << " "; #define show(a) cout << (a) << endl; #define show2(a, b) cout << (a) << " " << (b) << endl; #define show3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl; #define show4(a, b, c, d) cout << (a) << " " << (b) << " " << (c) << " " << (d) << endl; #define showif(f, a, b) if(f) cout << (a) << endl; else cout << (b) << endl; #define dshow(x, n) cout << fixed << setprecision(n) << (x) << endl; #define bshow(a, n) show(bitset(a)) #define pshow(a) show2((a).first, (a).second) #define pshown(a) shown2((a).first, (a).second) #define pshow2(a, b) pshown(a) pshow(b) #define ishow(a) show(inf(a)) #define yes(f) show(f ? "Yes" : "No") #define vshown(A) vcrep(a, A) { shown(a) } el #define vshow(A) vcrep(a, A) { show(a) } #define vvshow(A) vcrep(a, A) { vshown(a) } #define vbshown(A, n) vcrep(a, A) { shown(bitset(a)) } el #define vbshow(A, n) vcrep(a, A) { show(bitset(a)) } #define vvbshow(A, n) vcrep(a, A) { vbshow(a, n) } #define vpshow(A) vcrep(a, A) { pshow(a) } #define vishow(A) vcrep(a, A) { shown(inf(a)) } el #define vvishow(A) vcrep(a, A) { vishow(a) } const LI INF = (1LL << 60); //const LI MOD = 998244353; const LI MOD = 1000000007; const LD PI = acos(-1); class MAT { private: LI mod; public: MAT(LI mod_) : mod(mod_) {} void tr(LI& n) { n = (n + mod) % mod; } VVI x(const VVI& A, const VVI& B) { VVI res(A.size(), VI(A.size(), 0)); rep(i, A.size()) rep(j, B[0].size()) rep(k, A[i].size()) { res[i][j] += A[i][k] * B[k][j]; tr(res[i][j]); } return res; } VVI matpow(VVI A, LI N) { VVI res(A.size(), VI(A.size(), 0)); rep(i, A.size()) res[i][i] = 1; while (N) { if (N & 1) res = x(res, A); A = x(A, A); N >>= 1; } return res; } }; int seisen_109() { iscan2(N, M); VVI A = { { 1, 1 }, { 1, 0 } }; MAT mat(M); auto B = mat.matpow(A, N - 1); show(B[1][0]); return 0; } int main() { seisen_109(); return 0; }