#include #include #include using namespace std; #define rep(i,n) for(int i=0;i=0;i--) #define Rrep1(i,n) for(int i=n;i>0;i--) #define all(a) a.begin(),a.end() using ll = long long; using ull = unsigned long long; using vi = vector; using vvi = vector; using vvvi = vector; using vl = vector; using vvl = vector; using vvvl = vector; #define INF ((ll)2e18) #define IINF ((int)(1e9+5e8)) const double PI = 3.1415926535897932384626433832795028841971; templateinline bool chmax(T& a, T b) { return ((a < b) ? (a = b, true) : (false)); } templateinline bool chmin(T& a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define yesno(ans) cout<<((ans)?"Yes\n":"No\n") bool eq(double a, double b) { return abs(a - b) < 0.0000001; } //LRUD //const int di[4] = { 0,-1,0,1 }; //const int dj[4] = { -1,0,1,0 }; const int di[8] = { 0,0,1,1,1,-1,-1,-1 }; const int dj[8] = { 1,-1,0,-1,1,0,-1,1 }; ///*ACL #include using namespace atcoder; using mint=modint; //using mint = modint998244353; //using mint = modint1000000007; using vm = vector; using vvm = vector; using vvvm = vector; //*/ random_device seed_gen; mt19937 rnd(seed_gen()); using vec=vm; using mat=vvm; //A*B mat mul(mat &A,mat &B){ mat C(A.size(),vec(B[0].size())); for(int i=0;i0){ if(n&1)B=mul(B,A); A=mul(A,A); n>>=1; } return B; } int solve() { ll N,M;cin>>N>>M; mint::set_mod(M); mat A(2,vec(2)); A[0][0]=1;A[0][1]=1; A[1][0]=1;A[1][1]=0; A=pow(A,N-1); cout<