// #include #include int main() { using namespace std; // using modint = atcoder::static_modint<998244353>; unsigned long N, M, K; cin >> N >> M >> K; auto g{gcd(M, K)}; vector prime_factors; for (unsigned long p{2}; p * p <= g; ++p) if (g % p == 0) { prime_factors.emplace_back(p); while (g % p == 0) g /= p; } if(g > 1)prime_factors.emplace_back(g); const auto P{size(prime_factors)}; auto M_p{M}; vector counter(60, 1); for (unsigned long i{}; i < P; ++i) { const auto p{prime_factors[i]}; unsigned long x_M{1}, x_K{1}; while (M_p % p == 0) { M_p /= p; x_M *= p; } while (K % (x_K * p) == 0) x_K *= p; unsigned long x{1}; for (unsigned long j{}; j < 60; ++j) { counter[j] *= x; x = min(x_M, x * x_K); } } for (unsigned long j{60}; --j;) counter[j] -= counter[j - 1]; while (counter.back() == 0) counter.pop_back(); counter.emplace_back(M / M_p * (M_p - 1)); for (const auto c : counter) cout << c << " "; cout << endl; const auto C{size(counter)}; vector matrix(C, vector(C)); for (unsigned long i{}; i < C; ++i) { for (unsigned long j{}; j < C; ++j) matrix[i][j] = counter[j]; matrix[i][i - (i && i + 1 < C)] -= 1; } for (const auto &row : matrix) { for (const auto c : row) cout << c << " "; cout << endl; } cout << endl; vector ans(C, vector(C)); for (unsigned long i{}; i < C; ++i) ans[i][i] = 1; const auto multiply{ [C](const auto &lhs, const auto &rhs) { vector ret(C, vector(C)); for (unsigned long i{}; i < C; ++i) { for (unsigned long j{}; j < C; ++j) { for (unsigned long k{}; k < C; ++k) { ret[i][k] += lhs[i][j] * rhs[j][k] % 998244353; } } } for (auto &&row : ret) for (auto &&x : row) x %= 998244353; return ret; }}; while (N) { if (N & 1) ans = multiply(ans, matrix); matrix = multiply(matrix, matrix); N /= 2; } cout << ans[0][0] << endl; return 0; }