// हर हर महादेव using namespace std; #include #define ll long long int #define ld long double #define uid(a, b) uniform_int_distribution(a, b)(rng) mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count()); #ifdef shivang_ka_laptop #define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__); #define booga cerr << "booga" << endl; #else #define debug(...) 42; #define booga 9; #endif template std::ostream& operator<<(std::ostream& stream, const vector& vec){ for(size_t i = 0; i < vec.size(); i++){stream << vec[i];if(i != vec.size() - 1)stream << ' ';}; return stream; } template std::istream& operator>>(std::istream& stream, vector& vec) { for(T &x : vec)stream >> x;return stream; } template std::ostream& operator<<(std::ostream& stream, const pair& pr){ stream << pr.first << ' ' << pr.second; return stream; } template std::istream& operator>>(std::istream& stream, pair& pr){ stream >> pr.first >> pr.second; return stream; } template void operator+=(vector& vec, const U value) { for(T &x : vec)x += value; } template void operator-=(vector& vec, const U value) { for(T &x : vec)x -= value; } template void operator*=(vector& vec, const U value) { for(T &x : vec)x *= value; } template void operator/=(vector& vec, const U value) { for(T &x : vec)x /= value; } template void operator++(vector& vec) { vec += 1; } template void operator++(vector& vec,int) { vec += 1; } template void operator--(vector& vec) { vec -= 1; } template void operator--(vector& vec,int) { vec -= 1; } template void operator+=(pair& vec, const V value) { vec.first += value;vec.second += value; } template void operator-=(pair& vec, const V value) { vec.first -= value;vec.second -= value; } template void operator*=(pair& vec, const V value) { vec.first *= value;vec.second *= value; } template void operator/=(pair& vec, const V value) { vec.first /= value;vec.second /= value; } template void operator++(pair& vec) { vec += 1; } template void operator++(pair& vec,int) { vec += 1; } template void operator--(pair& vec) { vec -= 1; } template void operator--(pair& vec,int) { vec -= 1; } template string to_string(pair p); template string to_string(tuple p); template string to_string(tuple p); string to_string(const string& s) { return '"' + s + '"'; } string to_string(char c) {string s;s += c;return s; } string to_string(const char* s) {return to_string((string) s); } string to_string(bool b) {return (b ? "1" : "0"); } string to_string(vector v) {bool first = true;string res = "{";for (int i = 0; i < static_cast(v.size()); i++) {if (!first) {res += ", ";}first = false;res += to_string(v[i]);}res += "}";return res;} template string to_string(bitset v) {string res = "";for (size_t i = 0; i < N; i++) {res += static_cast('0' + v[i]);}return res;} template string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;} template string to_string(pair p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";} template string to_string(tuple p) {return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";} template string to_string(tuple p) {return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";} template bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; } template bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; } void debug_out() { cerr << endl; } template void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);} void bharo(int N_N) { return; }template void bharo(int N_N, Head &H, Tail & ... T) {H.resize(N_N);bharo(N_N,T...);} void safai() { return; }template void safai(Head &H, Tail & ... T) {H.clear();safai(T...);} template T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u; } template class Modular { public: using Type = typename decay::type; constexpr Modular() : value() {} template Modular(const U& x) { value = normalize(x); } template static Type normalize(const U& x) { Type v; if (-mod() <= x && x < mod()) v = static_cast(x); else v = static_cast(x % mod()); if (v < 0) v += mod(); return v; } const Type& operator()() const { return value; } template explicit operator U() const { return static_cast(value); } constexpr static Type mod() { return T::value; } Modular& operator+=(const Modular& other) { if ((value += other.value) >= mod()) value -= mod(); return *this; } Modular& operator-=(const Modular& other) { if ((value -= other.value) < 0) value += mod(); return *this; } template Modular& operator+=(const U& other) { return *this += Modular(other); } template Modular& operator-=(const U& other) { return *this -= Modular(other); } Modular& operator++() { return *this += 1; } Modular& operator--() { return *this -= 1; } Modular operator++(int) { Modular result(*this); *this += 1; return result; } Modular operator--(int) { Modular result(*this); *this -= 1; return result; } Modular operator-() const { return Modular(-value); } template typename enable_if::Type, int>::value, Modular>::type& operator*=(const Modular& rhs) { #ifdef _WIN32 uint64_t x = static_cast(value) * static_cast(rhs.value); uint32_t xh = static_cast(x >> 32), xl = static_cast(x), d, m; asm( "divl %4; " : "=a" (d), "=d" (m) : "d" (xh), "a" (xl), "r" (mod()) ); value = m; #else value = normalize(static_cast(value) * static_cast(rhs.value)); #endif return *this; } template typename enable_if::Type, long long>::value, Modular>::type& operator*=(const Modular& rhs) { long long q = static_cast(static_cast(value) * rhs.value / mod()); value = normalize(value * rhs.value - q * mod()); return *this; } template typename enable_if::Type>::value, Modular>::type& operator*=(const Modular& rhs) { value = normalize(value * rhs.value); return *this; } Modular& operator/=(const Modular& other) { return *this *= Modular(inverse(other.value, mod())); } friend const Type& abs(const Modular& x) { return x.value; } template friend bool operator==(const Modular& lhs, const Modular& rhs); template friend bool operator<(const Modular& lhs, const Modular& rhs); template friend V& operator>>(V& stream, Modular& number); private: Type value; }; template bool operator==(const Modular& lhs, const Modular& rhs) { return lhs.value == rhs.value; } template bool operator==(const Modular& lhs, U rhs) { return lhs == Modular(rhs); } template bool operator==(U lhs, const Modular& rhs) { return Modular(lhs) == rhs; } template bool operator!=(const Modular& lhs, const Modular& rhs) { return !(lhs == rhs); } template bool operator!=(const Modular& lhs, U rhs) { return !(lhs == rhs); } template bool operator!=(U lhs, const Modular& rhs) { return !(lhs == rhs); } template bool operator<(const Modular& lhs, const Modular& rhs) { return lhs.value < rhs.value; } template Modular operator+(const Modular& lhs, const Modular& rhs) { return Modular(lhs) += rhs; } template Modular operator+(const Modular& lhs, U rhs) { return Modular(lhs) += rhs; } template Modular operator+(U lhs, const Modular& rhs) { return Modular(lhs) += rhs; } template Modular operator-(const Modular& lhs, const Modular& rhs) { return Modular(lhs) -= rhs; } template Modular operator-(const Modular& lhs, U rhs) { return Modular(lhs) -= rhs; } template Modular operator-(U lhs, const Modular& rhs) { return Modular(lhs) -= rhs; } template Modular operator*(const Modular& lhs, const Modular& rhs) { return Modular(lhs) *= rhs; } template Modular operator*(const Modular& lhs, U rhs) { return Modular(lhs) *= rhs; } template Modular operator*(U lhs, const Modular& rhs) { return Modular(lhs) *= rhs; } template Modular operator/(const Modular& lhs, const Modular& rhs) { return Modular(lhs) /= rhs; } template Modular operator/(const Modular& lhs, U rhs) { return Modular(lhs) /= rhs; } template Modular operator/(U lhs, const Modular& rhs) { return Modular(lhs) /= rhs; } template Modular power(const Modular& a, const U& b) { assert(b >= 0); Modular x = a, res = 1; U p = b; while (p > 0) { if (p & 1) res *= x; x *= x; p >>= 1; } return res; } template bool IsZero(const Modular& number) { return number() == 0; } template string to_string(const Modular& number) { return to_string(number()); } // U == std::ostream? but done this way because of fastoutput template U& operator<<(U& stream, const Modular& number) { return stream << number(); } // U == std::istream? but done this way because of fastinput template U& operator>>(U& stream, Modular& number) { typename common_type::Type, long long>::type x; stream >> x; number.value = Modular::normalize(x); return stream; } //using ModType = int; //struct VarMod { static ModType value; }; //ModType VarMod::value; //ModType& md = VarMod::value; //using Mint = Modular; //constexpr int md = (int) 1e9 + 7; constexpr int md = 998244353; using Mint = Modular::type, md>>; Mint power(int x,const long long int y){ return power(Mint(x),y); } /* vector fact(1, 1); vector inv_fact(1, 1); const int MXN = ; void prep(){ // Don't forget to call this to use nCr fact.resize(MXN); inv_fact.resize(MXN); fact[0] = 1; for(int i = 1; i < MXN; i++){ fact[i] = fact[i-1]*i; } inv_fact[MXN-1] = power(fact[MXN-1],md-2); for(int i = MXN-2; i >= 0; i--){ inv_fact[i] = inv_fact[i+1]*(i+1); } } Mint C(int n, int k) { if (k < 0 || k > n) { return 0; } while ((int) fact.size() < n + 1) { fact.push_back(fact.back() * (int) fact.size()); inv_fact.push_back(1 / fact.back()); } return fact[n] * inv_fact[k] * inv_fact[n - k]; } */ Mint sum(int n){ if(n <= 0){ return 0; } return (Mint)n * (n + 1) / 2; } Mint sumsq(int n){ return (Mint)n * (n + 1) * (Mint)(2*n + 1) / 6; } Mint sumsum(int n){ if(n <= 0){ return 0; } Mint tot = sumsq(n); tot += sum(n); tot /= 2; return tot; } Mint sumsum(int l,int r){ return sumsum(r) - sumsum(l-1); } vector get(int n){ set all; for(int i = 1; i*i <= n; i++){ all.insert(i); all.insert(n / i); } return vector(all.begin(),all.end()); } int low(int n,int k){ int l = 1,r = n,ans = -1; while(l <= r){ int m = (l + r) >> 1; int v = n / m; if(v <= k){ ans = m; r = m - 1; } else{ l = m + 1; } } return ans; } int high(int n,int k){ int l = 1,r = n,ans = -1; while(l <= r){ int m = (l + r) >> 1; int v = n / m; if(v >= k){ ans = m; l = m + 1; } else{ r = m - 1; } } return ans; } vector> rang(int n){ auto a = get(n); vector> res; for(int x : a){ int l = low(n,x),r = high(n,x); res.push_back({x,l,r}); } return res; } Mint super(Mint a,Mint d,int n){ Mint ans = 0; ans += n * a * a; ans += a * d * sum(n-1); ans += a * n; ans += a * d * sum(n-1); ans += d * d * sumsq(n-1); ans += d * sum(n-1); ans /= 2; return ans; } void testcase(){ int n,m; //#ifdef shivang_ka_laptop //n = uid(1,10); //m = uid(1,10); //#endif cin >> n >> m; Mint ans = 0; auto res = rang(n); for(auto p : res){ int x = p[0],l = p[1],r = p[2]; if(l > m){ continue; } if(r >= m){ r = m; } ans += (Mint)x * sumsum(l-1,r-1); } Mint ans2 = 0; for(auto p : res){ int x = p[0],l = p[1],r = p[2]; if(l > m){ continue; } if(r >= m){ r = m; } int a = n % r; int d = x; int term = r - l + 1; Mint tmp = super(a,d,term); ans2 += tmp; } if(m > n){ ans2 += (Mint)sum(n) * (m-n); } cout << ans + ans2; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int tt = 1; //cin >> tt; while(tt--){ testcase(); } return (0-0); }