#include //#include using namespace std; #define rep(i,n) for(ll i=0; i=0; i--) #define fi first #define se second long long mo = 1000000007; typedef long long ll; typedef long double ld; typedef pair Pii; typedef pair Pll; typedef pair PlP; template void cmin(T &a, const S &b) { if (a > b)a = b; } template void cmax(T &a, const S &b) { if (a < b)a = b; } templatevoid PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout< void drop(const T &x){cout< matmul(vector &dp, vector> &mt){ // vector ret(m,0); // rep(i,m)rep(j,m) ret[i] += mt[i][j]*dp[j]; // return ret; // } // // 遷移行列の更新 // vector> update(vector> &mt){ // vector> ret(m, vector(m,0)); // rep(i,m)rep(j,m)rep(k,m) ret[i][j] += mt[i][k] + mt[k][j]; // return ret; // } // void matpow(vector &dp, vector> &mt, ll k){ // ll m = dp.size(); // while(k){ // if(k&1LL) dp = matmul(dp,mt); // mt = update(mt); // k /= 2; // } // } ll M; ll m; // 遷移行列のサイズ // dpの更新 vector matmul(vector &dp, vector> &mt){ vector ret(m,0); rep(i,m)rep(j,m) { ret[i] += mt[i][j]*dp[j]; ret[i] %= M; } return ret; } // 遷移行列の更新 vector> update(vector> &mt){ vector> ret(m, vector(m,0)); rep(i,m)rep(j,m)rep(k,m) { ret[i][j] += mt[i][k] * mt[k][j]; ret[i][j] %= M; } return ret; } void matpow(vector &dp, vector> &mt, ll k){ ll m = dp.size(); while(k){ if(k&1LL) dp = matmul(dp,mt); mt = update(mt); k /= 2; } } int main(){ ll N; m = 2; cin >> N >> M; vector dp(2); vector> mt(2, vector(2)); dp[0] = 0; dp[1] = 1; mt[0][0] = mt[0][1] = mt[1][0] = 1; mt[1][1] = 0; matpow(dp,mt,N); cout << dp[1] << endl; } /* int main(){ ll N,M; cin >> N >> M; vector F(100); F[0] = 0; F[1] = 1; rep(i,N){ F[(i+2)%100] = F[(i+1)%100] + F[i%100]; F[(i+2)%100] %= M; } cout << F[(N-1)%100] << endl; }*/