#pragma GCC optimize("O3", "unroll-loops") #include using namespace std; #define ll long long constexpr ll mod = 1000000007LL; struct Matrix { int n; vector> element; Matrix(int n) : n(n) { element.resize(n); for (int i = 0; i < n; ++i) element[i].resize(n, 0); } Matrix operator *(Matrix a) { assert(n == a.n); Matrix res(n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { ll tmp = 0; for (int k = 0; k < n; ++k) { tmp += element[i][k] * a.element[k][j] % mod; tmp %= mod; } res.element[i][j] = tmp; } } return res; } Matrix pow(ll k) { if (k == 0) { Matrix res(n); for (int i = 0; i < n; ++i) res.element[i][i] = 1; return res; } Matrix tmp = pow(k / 2); if (k % 2 == 1) return tmp * tmp * (*this); return tmp * tmp; } }; int main(void){ int M, K; cin >> M >> K; Matrix m(M); for (int i = 0; i < M; ++i) for (int p = 0; p < M; ++p) ++m.element[(i + p) % M][i], ++m.element[(i * p) % M][i]; m = m.pow(K); cout << m.element[0][0] << endl; return 0; }