/*** author: yuji9511 ***/ #include using namespace std; using ll = long long; using lpair = pair; const ll MOD = 1e9+7; const ll INF = 1e18; #define rep(i,m,n) for(ll i=(m);i<(n);i++) #define rrep(i,m,n) for(ll i=(m);i>=(n);i--) #define printa(x,n) for(ll i=0;i void print(H&& h, T&&... t){cout<(t)...);} typedef vector vec; typedef vector mat; mat mult(mat &A, mat &B){ mat C(A.size(), vec(B[0].size(),0)); rep(i,0,A.size()){ rep(k,0,B.size()){ rep(j,0,B[0].size()){ C[i][j] += A[i][k] * B[k][j]; C[i][j] %= MOD; } } } return C; } mat pow_mat(mat A, ll n){ if(n == 1) return A; if(n % 2 == 0){ mat B = pow_mat(A, n/2); return mult(B,B); }else{ mat B = pow_mat(A, n-1); return mult(A,B); } } int main(){ cin.tie(0); ios::sync_with_stdio(false); ll M,K; cin >> M >> K; mat A(M, vec(M,0)); rep(j,0,M){ rep(k,0,M){ A[j * k % M][j]++; A[(j + k) % M][j]++; } } mat ans = pow_mat(A, K); print(ans[0][0]); }