#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } constexpr long long MAX = 5100000; constexpr long long INF = 1LL << 60; constexpr int inf = 1000000007; constexpr long long mod = 1000000007LL; //constexpr long long mod = 998244353LL; using namespace std; typedef unsigned long long ull; typedef long long ll; struct mint { long long x; mint(long long x = 0) :x((x% mod + mod) % mod) {} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod - a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res += a; } mint operator-(const mint a) const { mint res(*this); return res -= a; } mint operator*(const mint a) const { mint res(*this); return res *= a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t >> 1); a *= a; if (t & 1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod - 2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res /= a; } }; struct Matrix { vector > val; Matrix(int n, int m, mint x = 0) : val(n, vector(m, x)) {} size_t size() const { return val.size(); } inline vector& operator [] (int i) { return val[i]; } }; Matrix operator * (Matrix A, Matrix B) { Matrix R(A.size(), B[0].size()); for (int i = 0; i < A.size(); ++i) for (int j = 0; j < B[0].size(); ++j) for (int k = 0; k < B.size(); ++k) R[i][j] = (R[i][j] + A[i][k] * B[k][j]); return R; } Matrix modpow(Matrix A, long long n) { Matrix R(A.size(), A.size()); for (int i = 0; i < A.size(); ++i) R[i][i] = 1; while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; } return R; } int main() { /* cin.tie(nullptr); ios::sync_with_stdio(false); */ ll M, K; scanf("%lld %lld", &M, &K); Matrix mat(M, M); for (int i = 0; i < M; i++) for (int j = 0; j < M; j++) mat[i][j] += 1; for (int i = 0; i < M; i++) { for (int j = 0; j < M; j++) { ll next = i * j % M; mat[next][i] += 1; } } Matrix ini(M, 1); ini[0][0] = 1; Matrix res = modpow(mat, K) * ini; cout << res[0][0].x << "\n"; return 0; }