#include using namespace std; typedef long long ll; typedef long double ld; #define rep(i,n) for (int i = 0; i < (n); ++i) templatebool chmax(T &a, const T &b) { if (abool chmin(T &a, const T &b) { if (b= mod) x -= mod; return *this; } constexpr mint& operator-=(const mint& a){ if((x += mod-a.x) >= mod) x -= mod; return *this; } constexpr mint& operator*=(const mint& a){ (x *= a.x) %= mod; return *this; } constexpr mint operator+(const mint& a) const{ mint res(*this); return res+=a; } constexpr mint operator-(const mint& a) const{ mint res(*this); return res-=a; } constexpr mint operator*(const mint& a) const{ mint res(*this); return res*=a; } constexpr mint pow(long long x) const{ if(!x) return 1; mint a = pow(x>>1); a *= a; if(x&1) a *= *this; return a; } constexpr mint inv() const{ return pow(mod-2); } constexpr mint& operator/=(const mint& a){ return (*this) *= a.inv(); } constexpr mint operator/(const mint& a) const{ mint res(*this); return res/=a; } friend ostream& operator<<(ostream& os, const mint& m){ os << m.x; return os; } }; int m; vector matmul(vector &dp,vector> &mt){ vector ret(m); rep(i,m){ rep(j,m){ ret[i]+=mt[i][j]*dp[j]; } } return ret; } vector> update(vector> &mt){ vector> ret(m,vector(m)); rep(i,m){ rep(j,m){ rep(l,m){ ret[i][j]+=mt[i][l]*mt[l][j]; } } } return ret; } void matpow(vector &dp,vector> &mt,ll k){ while(k){ if(k&1){ dp=matmul(dp,mt); } mt=update(mt); k/=2; } } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll k;cin >> m >> k; vector dp(m); vector> mt(m,vector(m)); dp[0]=1; rep(i,m){ rep(j,m){ mt[(i+j)%m][i]+=1; mt[i*j%m][i]+=1; } } matpow(dp,mt,k); cout << dp[0] << endl; }