#pragma GCC target("avx") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; #define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i)) constexpr ll mod = 1000000007; inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); } templateinline vector vec(size_t a) { return vector(a); } templateinline vector defvec(T def, size_t a) { return vector(a, def); } templateinline auto vec(size_t a, Ts... ts) { return vector(ts...))>(a, vec(ts...)); } templateinline auto defvec(T def, size_t a, Ts... ts) { return vector(def, ts...))>(a, defvec(def, ts...)); } inline void print() { cout << "\n"; } templateinline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); } struct matrix { int n, m; vector> dat; matrix(const vector>& _a) : dat(_a) { n = dat.size(), m = dat.front().size(); } matrix(const int& _n, const int& _m) : n(_n), m(_m) { dat = vec(n, m); } matrix operator*=(const matrix& a) { assert(m == a.n); matrix ret(vec(n, a.m)); FOR(i, 0, n)FOR(k, 0, m)FOR(j, 0, a.m) { ret[i][j] += dat[i][k] * a.dat[k][j] % mod; if (mod <= ret[i][j])ret[i][j] -= mod; } return *this = ret; } matrix operator*(const matrix& a) { return matrix(*this) *= a; } matrix pow(ll k) const { assert(n == m); matrix ret(vec(n, n)), a(dat); FOR(i, 0, n)ret[i][i] = 1; for (; 0 < k; k >>= 1) { if (k & 1)ret*= a; a*= a; } return ret; } vector& operator[](int i) { return dat[i]; } }; int main() { init(); int m, k; cin >> m >> k; matrix x(m, m), y(m, m); x[0][0] = 1; FOR(i, 0, m)FOR(j, 0, m) { ++y[i][(i + j) % m]; ++y[i][(i * j) % m]; } print((x * y.pow(k))[0][0]); }