import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top * * @author silviase */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); No1050ZeroMaximum solver = new No1050ZeroMaximum(); solver.solve(1, in, out); out.close(); } static class No1050ZeroMaximum { public void solve(int testNumber, Scanner in, PrintWriter out) { final int MOD = (int) 1e9 + 7; int m = in.nextInt(); int k = in.nextInt(); // 最右項, 始めは1,0,0,0...0 long[][] res = new long[m][1]; res[0][0] = 1; // i->jに行く組み合わせ.addがあるので全て1からスタートする. long[][] mt = new long[m][m]; ArrayUtil.fill(mt, 1); for (int from = 0; from < m; from++) { for (int mul = 0; mul < m; mul++) { mt[from][(from * mul) % m]++; } } Matrix ans = Matrix.mul(Matrix.pow(new Matrix(mt), k, MOD), new Matrix(res), MOD); out.println(ans.m[0][0]); } } static class ArrayUtil { public static void fill(long[][] array, long val) { for (long[] a : array) Arrays.fill(a, val); } } static class Matrix { public long[][] m; public int h; public int w; public Matrix(int h, int w, long[][] m) { this.h = h; this.w = w; this.m = m; } public Matrix(long[][] m) { this.m = m; this.h = m.length; this.w = m[0].length; } public static Matrix identity(int n) { long[][] mat = new long[n][n]; for (int i = 0; i < n; i++) { mat[i][i] = 1; } return new Matrix(mat); } public static Matrix mul(Matrix m1, Matrix m2, long MOD) { long[][] res = new long[m1.h][m2.w]; long[][] mat1 = m1.m; long[][] mat2 = m2.m; for (int h = 0; h < m1.h; h++) { for (int w = 0; w < m2.w; w++) { for (int x = 0; x < m1.w; x++) { res[h][w] += mat1[h][x] * mat2[x][w]; res[h][w] %= MOD; } } } return new Matrix(res); } public static Matrix pow(Matrix m, long a, long MOD) { if (a == 0) return identity(m.h); Matrix half = pow(m, a / 2, MOD); return mul(mul(half, half, MOD), a % 2 == 0 ? identity(m.h) : m, MOD); } } }