#include #include #include using namespace std; long long MOD = 1e9 + 7; long long M, K; vector> gyo(vector> a, vector> b){ vector> A(M, vector (M)); for(int i = 0; i < M; i++){ for(int j = 0; j < M; j++){ long long res = 0; for(int k = 0; k < M; k++){ res += a[i][k]*b[k][j] % MOD; res %= MOD; } A[i][j] = res; } } return A; } vector> repow(vector> a, long long b){ vector> B(M, vector (M)); if(b == 1) return a; if(b % 2 == 0){ B = repow(a, b/2); return gyo(B, B); } else return gyo(repow(a, b - 1), a); } int main(){ cin >> M >> K; vector> dp(M, vector(M,0)); for(int i = 0; i < M; i++){ for(int j = 0; j < M; j++){ dp[i*j%M][i]++; dp[(i + j)%M][i]++; } } vector> ans; ans = repow(dp, K); cout << ans[0][0] << endl; }