#pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; template class y_combinator { F f; public: y_combinator(F&& f) : f(std::forward(f)) {} template auto operator()(Args&&... args) const { return f(*this, std::forward(args)...); } }; constexpr int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1}; constexpr int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1}; using ll = long long; using u32 = unsigned int; using u64 = unsigned long long; using vi = vector; using vl = vector; using pii = pair; using pll = pair; template using vc = vector; template using vvc = vector>; template > using prique = priority_queue, U>; #define overload(a, b, c, d, e, ...) e #define len(x) (ll)(x.size()) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define rep1(n) for (ll _ = 0; _ < ll(n); _++) #define rep2(i, n) for (ll i = 0; i < ll(n); i++) #define rep3(i, a, b) for (ll i = ll(a); i < ll(b); i++) #define rep4(i, a, b, c) for (ll i = ll(a); i < ll(b); i += ll(c)) #define rep(...) overload(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__) #define rrep(i, n) for (ll i = ll(n) - 1; i >= 0; i--) template void dedup(vector& a) { sort(all(a)), a.erase(unique(all(a)), a.end()); } template bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } template bool chmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; } namespace cppio { template struct is_tuple_like : false_type {}; template struct is_tuple_like> : true_type {}; template struct is_tuple_like> : true_type {}; template struct is_container : false_type {}; template struct is_container()))>> : bool_constant, string> && !is_same_v, char*> && !is_same_v, const char*> && !is_array_v>> {}; template void _in(T& x) { if constexpr (is_tuple_like::value) apply([](auto&... elems) { (_in(elems), ...); }, x); else if constexpr (is_container::value) { for (auto& e : x) _in(e); } else cin >> x; } template void _in_all(Ts&... args) { (_in(args), ...); } template void _out(const T& x) { bool first = true; if constexpr (is_tuple_like::value) { apply([&](const auto&... elems) { ((cout << (first ? "" : " "), _out(elems), first = false), ...); }, x); } else if constexpr (is_container::value) { for (const auto& e : x) { if (!first) cout << ' '; _out(e), first = false; } } else cout << x; } template void _print(const Ts&... args) { bool first = true; ((cout << (first ? "" : " "), _out(args), first = false), ...); } template void _out_all(const Ts&... args) { _print(args...), cout << '\n'; } template void _out_no_el(const Ts&... args) { _print(args...); } } // namespace cppio #define IN(...) cppio::_in_all(__VA_ARGS__) #define OUT(...) cppio::_out_all(__VA_ARGS__) #define out(...) cppio::_out_no_el(__VA_ARGS__) #define INT(...) int __VA_ARGS__; IN(__VA_ARGS__) #define LL(...) ll __VA_ARGS__; IN(__VA_ARGS__) #define STR(...) string __VA_ARGS__; IN(__VA_ARGS__) #define CHR(...) char __VA_ARGS__; IN(__VA_ARGS__) #define DBL(...) double __VA_ARGS__; IN(__VA_ARGS__) #define VEC(type, name, size) vector name(size); IN(name) #define VV(type, name, h, w) vector> name(h, vector(w)); IN(name) #define RETURN(...) do { __VA_ARGS__; return; } while (0) bool Yes(bool b = true) { OUT(b ? "Yes" : "No"); return b; } bool No(bool b = true) { Yes(!b); return b; } bool YES(bool b = true) { OUT(b ? "YES" : "NO"); return b; } bool NO(bool b = true) { YES(!b); return b; } #ifdef ONLINE_JUDGE #define debug(...) (void(0)) #endif template struct Binom { private: std::vector _fact, _ifac; public: explicit Binom(size_t N = 0) : _fact(1, 1), _ifac(1, 1) { extend(N); } void extend(size_t N) { const size_t a = _fact.size(); if (a > N) return; _fact.resize(N + 1); for (size_t i = a; i <= N; i++) _fact[i] = _fact[i - 1] * i; _ifac.resize(N + 1); _ifac[N] = Mint{1} / _fact[N]; for (size_t i = N; i > a; i--) _ifac[i - 1] = _ifac[i] * i; } Mint fact(size_t x) { extend(x); return _fact[x]; } Mint invfact(size_t x) { extend(x); return _ifac[x]; } Mint perm(size_t N, size_t K) { if (N < K) return Mint{0}; return this->fact(N) * this->invfact(N - K); } Mint comb(size_t N, size_t K) { if (N < K) return Mint{0}; return this->fact(N) * this->invfact(K) * this->invfact(N - K); } Mint homo(size_t N, size_t K) { if (N == 0) return K == 0 ? Mint{1} : Mint{0}; return comb(N - 1 + K, K); } }; #include using mint = atcoder::modint998244353; const int maxn = 30'000'002; mint mu[maxn]; Binom C(maxn); void run_case() { INT(N, M); int L = min(N, M); for (int i = 1; i < maxn; i++) { mu[i] += C.fact(i - 1) * C.invfact(i); const mint v = mu[i]; for (int j = i + i; j < maxn; j += i) mu[j] -= v; } mint ans; const mint inv2 = mint::raw(2).inv(); rep(g, 1, L + 1) { mint a = mint::raw(N / g), b = mint::raw(M / g); mint ng = mint::raw(g); ans += mu[g] * a * b * ng * ng * (a + 1) * (b + 1); } ans *= inv2 * inv2; OUT(ans.val()); } int main() { std::ios_base::sync_with_stdio(false); std::cin.tie(nullptr); std::fixed(std::cout).precision(16); ll t = 1; while (t--) run_case(); }