//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 100010001; const ll LINF = (ll)INF*INF*10; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} const int mod = 1000000007; //const int mod = 998244353; struct mint { int64_t x; mint(int64_t x=0):x((x%mod+mod)%mod){} mint operator-() const { return mint(-x);} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;} mint operator+(const mint a) const { return mint(*this) += a;} mint operator-(const mint a) const { return mint(*this) -= a;} mint operator*(const mint a) const { return mint(*this) *= a;} mint pow(int64_t t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } //for prime mod mint inv() const { return pow(mod-2);} mint& operator/=(const mint a) { return *this *= a.inv();} mint operator/(const mint a) {return mint(*this) /= a;} }; istream& operator>>(istream& is, mint& a) { return is >> a.x;} ostream& operator<<(ostream& os, const mint& a) { return os << a.x;} //head using V = vector; using M = vector; M mul(const M a, const M b) { int n = a.size(); M res(n, V(n)); rep(i, n) rep(j, n) rep(k, n) { res[i][j] += a[i][k] * b[k][j]; } return res; } M pow(const M &a, const ll p) { int n = a.size(); if(!p) { M res(n, V(n)); rep(i, n) res[i][i] = 1; return res; } M res = pow(a, p>>1); res = mul(res, res); if(p&1) res = mul(res, a); return res; } int m; int k; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> m >> k; M mat(m, V(m)); rep(i, m) rep(j, m) { mat[(i+j)%m][j] += 1; mat[i*j%m][j] += 1; } mat = pow(mat, k); cout << mat[0][0] << endl; }