#define TO_BE_SUBMITTED #include // #include // #include // #include // #include // #include // #include #include // #include // #include // #include // #include // #include namespace atcoder{}; using namespace atcoder; using namespace std; #define fr first #define sc second #define rep(i, n) for (int i = 0; i < (n); ++i) #define rep1(i, n) for (int i = 1; i <= (n); ++i) #define rrep(i, n) for (int i = (n)-1; i >= 0; --i) #define rrep1(i, n) for (int i = (n); i >= 1; --i) #define srep(i, s, t) for (int i = s; i < t; ++i) #define rng(a) a.begin(), a.end() #define rrng(a) a.rbegin(), a.rend() #define isin(x, l, r) ((l) <= (x) && (x) < (r)) #define pb push_back #define eb emplace_back #define sz(x) (int)(x).size() #define pcnt __builtin_popcountll #define uni(x) x.erase(unique(rng(x)), x.end()) #define snuke srand((unsigned)clock() + (unsigned)time(NULL)); #define show(x) cout << #x << " = " << x << endl; #define PQ(T) priority_queue> #define bn(x) ((1 << x) - 1) #define dup(x, y) (((x) + (y)-1) / (y)) #define newline puts("") using ll = long long; using uint = unsigned; using ull = unsigned long long; using P = pair; using LP = pair; using vi = vector; using vvi = vector; using vl = vector; using vp = vector

; using vlp = vector; inline int getInt() { int x; scanf("%d", &x); return x; } template bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; } template bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; } using mint = modint; using vec = vector; using mat = vector; ll N, M; void showMat(mat a){ rep(h, 3){ cout << a[h][0].val() << " " << a[h][1].val() << " " << a[h][2].val() << "\n"; } cout << "\n"; } mat mul(mat a, mat b){ mat res(3, vec(3, 0)); rep(h, 3){ rep(w, 3){ rep(k, 3){ res[h][w] += a[h][k] * b[k][w]; } } } return res; } mat nijo(mat a){ return mul(a, a); } void solve() { cin >> N >> M; N--; modint::set_mod(M); ll n = N - 2; mat A(3, vec(3, 0)); A[0][0] = 1; A[0][1] = 1; A[1][0] = 1; A[2][1] = 1; mat B(3, vec(3, 0)); B[0][0] = 1; B[1][1] = 1; B[2][2] = 1; while(n > 0LL){ if((n & 1LL) == 1LL){ B = mul(B, A); } A = nijo(A); n /= 2LL; } cout << (B[0][0] + B[0][1]).val() << "\n"; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); solve(); return 0; }