#include using namespace std; constexpr int64_t mod = 1000000007; void matmul(vector> &x, const vector> &mat) { const int m = x.size(); vector> newmat(m, vector(m)); for (int i = 0; i < m; i++) { for (int k = 0; k < m; k++) { for (int j = 0; j < m; j++) { (newmat.at(i).at(j) += x.at(i).at(k) * mat.at(k).at(j) % mod) %= mod; } } } for (int i = 0; i < m; i++) { for (int j = 0; j < m; j++) { x.at(i).at(j) = newmat.at(i).at(j); } } } int main() { int m, k; cin >> m >> k; vector> mat0(m, vector(m)), mat(m, vector(m)); for (int i = 0; i < m; i++) { mat0.at(i).at(i) = 1; for (int j = 0; j < m; j++) { mat.at(i).at((i + j) % m)++; mat.at(i).at((i * j) % m)++; } } while (k) { if (k % 2) { matmul(mat0, mat); } matmul(mat, mat); k /= 2; } cout << mat0[0][0] << endl; }