Problem:
Cake Decoration
You are ordering a cake to celebrate the New Year. You have to decide the numbers of decoration items to be topped on the cake. Available items are dog figures, cat figures, red candies, and blue candies.
You want all four items to decorate the cake, and all the numbers of the four items to be different from each other. You also want the number of figures (the sum of dogs and cats) to be within a certain range.
An extra charge for the decoration items is added to the price of the cake. The extra is, although quite queer, the product of the numbers of the four decoration items. You want the cake to look gorgeous as far as the budget allows. Thus, you are not satisfied with a decoration if you can add any of the four items without violating the budget constraint.
The conditions stated above are summarized as follows. Let $d$, $c$, $r$, and $b$ be the numbers of dog figures, cat figures, red candies, and blue candies, respectively. All these numbers should be different positive integers satisfying the following conditions for given $X$, $L$, and $R$:
$L \leq d + c < R$,
$d \times c \times r \times b \leq X$,
$(d + 1) \times c \times r \times b > X$,
$d \times (c + 1) \times r \times b > X$,
$d \times c \times (r + 1) \times b > X$, and
$d \times c \times r \times (b + 1) > X$.
More than one combination of four numbers of decoration items may satisfy the conditions. Your task is to find how many such combinations exist.
Input
The input consists of a single test case of the following format.
$X$ $L$ $R$
Here, $X$, $L$, and $R$ are integers appearing in the conditions stated above. They satisfy $1 \leq X \leq
10^{14}$ and $1 \leq L < R \leq 10^{14}$.
Output
Output the number of combinations of four numbers of decoration items that satisfy the conditions stated above modulo a prime number $998 244 353 = 2^{23} \times 7 \times 17 + 1$.
Sample Input 1
24 4 6
Sample Output 1
12
Sample Input 2
30 5 6
Sample Output 2
4
Sample Input 3
30 9 20
Sample Output 3
0
Sample Input 4
100000000000000 1 100000000000000
Sample Output 4
288287412
For Sample Input 2, four combinations of $(d, c, r, b) = (2, 3, 1, 5), (2, 3, 5, 1), (3, 2, 1, 5)$, and $(3, 2, 5, 1)$ satisfy all the conditions. $(d, c, r, b) = (1, 4, 2, 3)$ is not eligible because its extra cost for the decoration items does not exceed $X = 30$ even after adding one more cat figure. $(d, c, r, b) = (1, 5, 2, 3)$ is also ineligible because $d + c < R = 6$ does not hold.

Submitted solutions:

code_snippet: #include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <cmath>
using namespace std;
using ll = long long;
const ll INF = 1ll << 60;
#define rep(i,n) for(int i=0; i<int(n); i++)

ll isqrt(ll v){
    ll w = sqrt(v);
    while(w*w > v) w--;
    while((w+1)*(w+1) <= v) w++;
    return w;
}

ll disqrt(ll v){
    ll w = isqrt(v);
    if(v / w == w) w--;
    return w;
}

const int MOD = 998244353;

int f(ll a, ll x, ll l){
    l = max(l, a);
    if(x < l) return 0;
    ll hx = disqrt(x);
    if(l <= hx) return (hx - l + 1) + (hx - a + 1);
    ll g = min(hx, x/l);
    return max<ll>(0, g-a+1);
}
int f2(ll a, ll x, ll l){
    int ans = 0;
    for(ll t=a; t*(t+1)<=x; t++){
        ll s = x / t;
        if(l <= t) ans++;
        if(l <= s) ans++;
    }
    return ans;
}

int subsolve(ll X, ll L){
    ll ans = 0;
    //for(ll a=1; a*a*a*a<=X; a++){
    //    for(ll b=a+1; a*b*(b+1)*(b+2)<=X; b++){
    //        for(ll c=b+1; a*b*c*(c+1)<=X; c++){
    //            ll d = X / (a*b*c);
    //            if(L <= a+b) ans += 4;
    //            //if(L <= a+c) ans += 4;
    //            //if(L <= a+d) ans += 4;
    //            //if(L <= b+c) ans += 4;
    //            //if(L <= b+d) ans += 4;
    //            if(L <= c+d) ans += 4;
    //        }
    //    }
    //}
    //return ans % MOD;
    // a < x < a , x
    // x < a < a , x
    for(ll a=1; a*a*a*a<=X; a++){
        for(ll b=a+1; a*b*(b+1)*(b+2)<=X; b++){
            ll x = X / (a*b);
            ans += f(b+1, x, L-a);
            ans += f(b+1, x, L-b);
        }
    }
    // a < a < x < x
    for(ll a=1; a*a*a*a<=X; a++){
        for(ll b=a+1; a*b*(b+1)*(b+2)<=X; b++){
            ll x = X / (a*b);
            ll cmin = b+1;
            ll cmax = disqrt(x);
            if(cmin + x/cmin < L) continue;
            {
                ll ok = cmin, ng = cmax+1;
                while(ng > ok + 1){
                    ll w = ng + (ok - ng) / 2;
                    (x/w + w < L ? ng : ok) = w;
                }
                cmax = ok;
            }
            if(cmin <= cmax){
                ans += (cmax - cmin + 1);
            }
        }
    }
    // x < x < a < a
    for(ll a=1; a*a*a*a<=X; a++){
        for(ll b=a+1; a*b*(b+1)*(b+2)<=X; b++) if(L <= a+b){
            ll x = X / (a*b);
            ll cmax = disqrt(x);
            ans += (cmax - b);
        }
    }
    ans %= MOD;
    ans *= 4;
    return ans % MOD;
}

void testcase(){
    ll X, L, R; cin >> X >> L >> R;
    ll ans = 0;
    ans += subsolve(X, L);
    ans += MOD - subsolve(X, R) % MOD;
    ans %= MOD;
    cout << ans << "\n";
}

int main(){
    cin.tie(0)->sync_with_stdio(0);
    //int T; cin >> T; rep(t,T)
    testcase();
    return 0;
}
accuracy: 1
time_ms: 2940
memory_kb: 3460
final_rank: 6

code_snippet: // AOJ #1440 Cake Decoration
// 2025.5.23

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;

ll calc(ll x, ll mx_sum) {
    ll ans = 0;
    for (ll a = 1; a * (a + 1) * (a + 2) * (a + 3) <= x; a++) {
        for (ll b = a + 1; a * b * (b + 1) * (b + 2) <= x; b++) {
            ll cd = x / (a*b);
            ll low = b + 1, high = sqrt(cd);
            if (high * (high + 1) > cd) high--;
            if (a + b < mx_sum) ans += max(0ll, high - low + 1);
            ans += max(0ll, min(high, mx_sum - a - 1) - low + 1);
            ans += max(0ll, min(high, mx_sum - b - 1) - low + 1);
            if (mx_sum > a) {
                ll t = cd / (mx_sum - a) + 1;
                ans += max(0ll, high - max(low, t) + 1);
            }
            if (mx_sum > b) {
                ll t = cd / (mx_sum - b) + 1;
                ans += max(0ll, high - max(low, t) + 1);
            }
            ll h = high;
            while (low <= h) {
                ll c = (low + h) / 2;
                if (c + (cd/c) < mx_sum) h = c - 1;
                else low = c + 1;
            }
            ans += max(0LL, high - low + 1);
        }
    }
    return (ans << 2) % MOD;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    ll x, l, r;
    cin >> x >> l >> r;
    ll ans = calc(x, r) - calc(x, l);
    if (ans < 0) ans += MOD;
    cout << ans << endl;
    return 0;
}
accuracy: 1
time_ms: 1830
memory_kb: 3460
final_rank: 3

code_snippet: #include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())

using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;

template <typename T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
    assert(y != 0);
    if (y < 0)
        x = -x, y = -y;
    return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
    return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
    return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
    return (x == 0 ? -1 : __builtin_ctzll(x));
}

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "P(" << p.first << ", " << p.second << ")";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end())
            os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
    cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
    for (; a[i] != ',' && a[i] != '\0'; i++)
        cerr << a[i];
    cerr << ":" << b << " ";
    _show(i + 1, a, c...);
}

/**
 * @brief template
 */

template <unsigned mod = 1000000007> struct fp {
    unsigned v;
    static constexpr int get_mod() {
        return mod;
    }
    constexpr unsigned inv() const {
        assert(v != 0);
        int x = v, y = mod, p = 1, q = 0, t = 0, tmp = 0;
        while (y > 0) {
            t = x / y;
            x -= t * y, p -= t * q;
            tmp = x, x = y, y = tmp;
            tmp = p, p = q, q = tmp;
        }
        if (p < 0)
            p += mod;
        return p;
    }
    constexpr fp(ll x = 0) : v(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    fp operator-() const {
        return fp() - *this;
    }
    fp pow(ull t) {
        fp res = 1, b = *this;
        while (t) {
            if (t & 1)
                res *= b;
            b *= b;
            t >>= 1;
        }
        return res;
    }
    fp &operator+=(const fp &x) {
        if ((v += x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator-=(const fp &x) {
        if ((v += mod - x.v) >= mod)
            v -= mod;
        return *this;
    }
    fp &operator*=(const fp &x) {
        v = ull(v) * x.v % mod;
        return *this;
    }
    fp &operator/=(const fp &x) {
        v = ull(v) * x.inv() % mod;
        return *this;
    }
    fp operator+(const fp &x) const {
        return fp(*this) += x;
    }
    fp operator-(const fp &x) const {
        return fp(*this) -= x;
    }
    fp operator*(const fp &x) const {
        return fp(*this) *= x;
    }
    fp operator/(const fp &x) const {
        return fp(*this) /= x;
    }
    bool operator==(const fp &x) const {
        return v == x.v;
    }
    bool operator!=(const fp &x) const {
        return v != x.v;
    }
    friend istream &operator>>(istream &is, fp &x) {
        return is >> x.v;
    }
    friend ostream &operator<<(ostream &os, const fp &x) {
        return os << x.v;
    }
};

// template <unsigned mod> void rd(fp<mod> &x) {
//     fastio::rd(x.v);
// }
// template <unsigned mod> void wt(fp<mod> x) {
//     fastio::wt(x.v);
// }

template <typename T> T Inv(ll n) {
    static const int md = T::get_mod();
    static vector<T> buf({0, 1});
    assert(n > 0);
    n %= md;
    while (SZ(buf) <= n) {
        int k = SZ(buf), q = (md + k - 1) / k;
        buf.push_back(buf[k * q - md] * q);
    }
    return buf[n];
}

template <typename T> T Fact(ll n, bool inv = 0) {
    static const int md = T::get_mod();
    static vector<T> buf({1, 1}), ibuf({1, 1});
    assert(n >= 0 and n < md);
    while (SZ(buf) <= n) {
        buf.push_back(buf.back() * SZ(buf));
        ibuf.push_back(ibuf.back() * Inv<T>(SZ(ibuf)));
    }
    return inv ? ibuf[n] : buf[n];
}

template <typename T> T nPr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nCr(int n, int r, bool inv = 0) {
    if (n < 0 || n < r || r < 0)
        return 0;
    return Fact<T>(n, inv) * Fact<T>(r, inv ^ 1) * Fact<T>(n - r, inv ^ 1);
}
template <typename T> T nHr(int n, int r, bool inv = 0) {
    return nCr<T>(n + r - 1, r, inv);
}

/**
 * @brief Modint
 */

using Fp = fp<998244353>;

void debug(string S, ll L, ll R) {
    //cout << S << ' ' << L << ' ' << R << endl;
}

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll X, L, R;
    cin >> X >> L >> R;
    Fp ANS = 0;
    for (ll A = 1; A * (A+1) * (A+2) * (A+3) <= X; A++) {
        for (ll B = A+1; A * B * (B+1) * (B+2) <= X; B++) {
            ll CD = X / (A*B);
            ll CMAX = sqrt(CD);
            if (A * B * CMAX * (CMAX + 1) > X) CMAX--;
            { //AB
                if (L <= A+B && A+B < R) ANS += CMAX - B;
                debug("AB", B+1, CMAX);
            }
            { //AC
                ll Left = max(B+1, L-A), Right = min(CMAX, R-A-1);
                if (Left <= Right) ANS += Right-Left+1;
                debug("AC", Left, Right);
            }
            { //AD
                ll Left = max(B+1, (R-A > 0 ? CD/(R-A)+1 : INF)), Right = min(CMAX, (L-A > 0 ? CD/(L-A) : INF));
                if (Left <= Right) ANS += Right-Left+1;
                debug("AD", Left, Right);
            }
            { //BC
                ll Left = max(B+1, L-B), Right = min(CMAX, R-B-1);
                if (Left <= Right) ANS += Right-Left+1;
                debug("BC", Left, Right);
            }
            { //BD
                ll Left = max(B+1, (R-B > 0 ? CD/(R-B)+1 : INF)), Right = min(CMAX, (L-B > 0 ? CD/(L-B) : INF));
                if (Left <= Right) ANS += Right-Left+1;
                debug("BD", Left, Right);
            }
            { //CD
                ll OK = B, NG = CMAX+1;
                while(NG - OK > 1) {
                    ll MID = (OK + NG) / 2;
                    if (MID + CD/MID >= L) OK = MID;
                    else NG = MID;
                }
                ll Right = OK;
                NG = B, OK = CMAX+1;
                while(OK - NG > 1) {
                    ll MID = (OK + NG) / 2;
                    if (MID + CD/MID < R) OK = MID;
                    else NG = MID;
                }
                ll Left = OK;
                if (Left <= Right) ANS += Right - Left + 1;
                debug("CD", Left, Right);
            }
        }
    }
    cout << ANS * 4 << endl;
}
accuracy: 1
time_ms: 2900
memory_kb: 3456
final_rank: 5

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int mod = 998244353;

ll calc(ll x, ll mx_sum) {
    ll res = 0;
    for (ll a = 1; a * (a + 1) * (a + 2) * (a + 3) <= x; a++) {
        for (ll b = a + 1; a * b * (b + 1) * (b + 2) <= x; b++) {
            ll cd = x / a / b;
            ll low = b + 1, high = sqrt(cd);
            if (high * (high + 1) > cd) high--;
            // a + b
            if (a + b < mx_sum) res += max(0ll, high - low + 1);
            // a + c, b + c
            res += max(0ll, min(high, mx_sum - a - 1) - low + 1);
            res += max(0ll, min(high, mx_sum - b - 1) - low + 1);
            // a + d < mx_sum, b + d < mx_sum
            if (mx_sum - a > 0) {
                ll mn_c = cd / (mx_sum - a) + 1;
                res += max(0ll, high - max(low, mn_c) + 1);
            }
            if (mx_sum - b > 0) {
                ll mn_c = cd / (mx_sum - b) + 1;
                res += max(0ll, high - max(low, mn_c) + 1);
            }
            // c + d
            ll h = high;
            while (low <= h) {
                ll c = (low + h) / 2;
                ll d = cd / c;
                if (c + d < mx_sum) h = c - 1;
                else low = c + 1;
            }
            res += max(0ll, high - low + 1);
        }
    }
    return res * 4 % mod;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef BACKER
        freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    #endif

    ll x, l, r;
    cin >> x >> l >> r;
    ll ans = calc(x, r);
    ans -= calc(x, l);
    cout << (ans + mod) % mod << "\n";
    
    return 0;
}
accuracy: 1
time_ms: 1830
memory_kb: 3448
final_rank: 2

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int mod = 998244353;

ll calc(ll x, ll mx_sum) {
    ll res = 0;
    for (ll a = 1; a * (a + 1) * (a + 2) * (a + 3) <= x; a++) {
        for (ll b = a + 1; a * b * (b + 1) * (b + 2) <= x; b++) {
            ll cd = x / a / b;
            ll low = b + 1, high = sqrt(cd);
            if (high * (high + 1) > cd) high--;
            // a + b
            if (a + b < mx_sum) res += max(0ll, high - low + 1);
            // a + c, b + c
            res += max(0ll, min(high, mx_sum - a - 1) - low + 1);
            res += max(0ll, min(high, mx_sum - b - 1) - low + 1);
            // a + d < mx_sum, b + d < mx_sum
            if (mx_sum - a > 0) {
                ll mn_c = cd / (mx_sum - a) + 1;
                res += max(0ll, high - max(low, mn_c) + 1);
            }
            if (mx_sum - b > 0) {
                ll mn_c = cd / (mx_sum - b) + 1;
                res += max(0ll, high - max(low, mn_c) + 1);
            }
            // c + d
            ll h = high;
            while (low <= h) {
                ll c = (low + h) / 2;
                ll d = cd / c;
                if (c + d < mx_sum) h = c - 1;
                else low = c + 1;
            }
            res += max(0ll, high - low + 1);
        }
    }
    return res * 4 % mod;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef BACKER
        freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    #endif

    ll x, l, r;
    cin >> x >> l >> r;
    ll ans = calc(x, r);
    ans -= calc(x, l);
    cout << ans % mod << "\n";
    
    return 0;
}
accuracy: 0.5
time_ms: 1780
memory_kb: 3484
final_rank: 10

code_snippet: #include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int mod = 998244353;

ll calc(ll x, ll mx_sum) {
    ll res = 0;
    for (ll a = 1; a * (a + 1) * (a + 2) * (a + 3) <= x; a++) {
        for (ll b = a + 1; a * b * (b + 1) * (b + 2) <= x; b++) {
            ll cd = x / a / b;
            ll low = b + 1, high = sqrt(cd);
            if (high * (high + 1) > cd) high--;
            // a + b
            if (a + b < mx_sum) res += max(0ll, high - low + 1);
            // a + c, b + c
            res += max(0ll, min(high, mx_sum - a - 1) - low + 1);
            res += max(0ll, min(high, mx_sum - b - 1) - low + 1);
            // a + d < mx_sum, b + d < mx_sum
            if (mx_sum - a > 0) {
                ll mn_c = cd / (mx_sum - a) + 1;
                res += max(0ll, high - max(low, mn_c) + 1);
            }
            if (mx_sum - b > 0) {
                ll mn_c = cd / (mx_sum - b) + 1;
                res += max(0ll, high - max(low, mn_c) + 1);
            }
            // c + d
            ll h = high;
            while (low <= h) {
                ll c = (low + h) / 2;
                ll d = cd / c;
                if (c + d < mx_sum) h = c - 1;
                else low = c + 1;
            }
            res += max(0ll, high - low + 1);
        }
    }
    return res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    #ifdef BACKER
        freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    #endif

    ll x, l, r;
    cin >> x >> l >> r;
    ll ans = calc(x, r);
    ans -= calc(x, l);
    cout << ans * 4 % mod << "\n";
    
    return 0;
}
accuracy: 1
time_ms: 1830
memory_kb: 3444
final_rank: 1

code_snippet: // #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;

ll f(ll R,ll X,ll u,ll d,ll up){
    while(up-d>1){
        ll mid=(up+d)/2;
        if(mid+X/(u*mid)<R)up=mid;
        else d=mid;
    }
    return up;
}
const ll mod=998244353;
int main() {
    ll X,L,R,an=0;
    cin>>X>>L>>R;
    for(ll w=1;w*(w+1)*(w+2)*(w+3)<=X;w++){
        for(ll x=w+1;w*x*(x+1)*(x+2)<=X;x++){
            if(x+1>=X/(x*w*(x+1)))break;
            ll sq=sqrt(X/(x*w));
            ll dw=max(x+1,sq-10),up=min(sq+10,X+1);
            while(up-dw>1){
                ll mid=(up+dw)/2;
                if(mid<X/(x*w*mid)){
                    dw=mid;
                }
                else up=mid;
            }
            if(L<=x+w&&x+w<R){
                an+=max(0ll,dw-x);
            }
            an+=max(0ll,min(R-w-1,dw)-max(L-w-1,x));
            an+=max(0ll,min(R-x-1,dw)-max(L-x-1,x));
            if(R>w){
                if(L>w){
                    an+=max(0ll,min((X/(L-w))/(x*w),dw)-max((X/(R-w))/(x*w),x));
                }
                else{
                    an+=max(0ll,dw-max((X/(R-w))/(x*w),x));
                }
            }
            an%=mod;
            if(R>x){
                if(L>x){
                    an+=max(0ll,min((X/(L-x))/(x*w),dw)-max((X/(R-x))/(x*w),x));
                }
                else{
                    an+=max(0ll,dw-max((X/(R-x))/(x*w),x));
                }
            }
            if(x+1+X/(x*w*(x+1))<L){
                continue;
            }
            if(dw+X/(x*w*dw)>=R){
                continue;
            }
            ll yR=f(R,X,x*w,x,dw);
            yR=max(x+1,yR);
            ll yL=f(L,X,x*w,max(x,yR-1),dw+1)-1;
            yL=min(dw,yL);
            an+=max(0ll,yL-yR+1);
            an%=mod;  
        }
    }
    an*=4;
    an%=mod;
    cout<<an<<endl;
}
accuracy: 1
time_ms: 3690
memory_kb: 3444
final_rank: 8

code_snippet: #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
#define per(i, n) for (int i = (n)-1; 0 <= i; i--)
#define rep2(i, l, r) for (int i = (l); i < int(r); i++)
#define per2(i, l, r) for (int i = (r)-1; int(l) <= i; i--)
#define MM << " " <<
#define pb push_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define sz(x) (int)x.size()
#define each(e, x) for (auto &e : x)
template <typename T>
void print(const vector<T> &v, T x = 0) {
    int n = v.size();
    for (int i = 0; i < n; i++)
        cout << v[i] + x << (i == n - 1 ? '\n' : ' ');
    if (v.empty())
        cout << '\n';
}
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
bool chmax(T &x, const T &y) {
    return (x < y) ? (x = y, true) : false;
}
template <typename T>
bool chmin(T &x, const T &y) {
    return (x > y) ? (x = y, true) : false;
}
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using maxheap = std::priority_queue<T>;
template <typename T>
int lb(const vector<T> &v, T x) {
    return lower_bound(begin(v), end(v), x) - begin(v);
}
template <typename T>
int ub(const vector<T> &v, T x) {
    return upper_bound(begin(v), end(v), x) - begin(v);
}
template <typename T>
void rearrange(vector<T> &v) {
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

// __int128_t gcd(__int128_t a, __int128_t b) {
//     if (a == 0)
//         return b;
//     if (b == 0)
//         return a;
//     __int128_t cnt = a % b;
//     while (cnt != 0) {
//         a = b;
//         b = cnt;
//         cnt = a % b;
//     }
//     return b;
// }

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

struct UnionFind {
    vector<int> data;
    int num;

    UnionFind(int sz) {
        data.assign(sz, -1);
        num = sz;
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y)
            return (false);
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        num--;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0)
            return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }

    int operator[](int k) {
        return find(k);
    }
};

template <int mod>
struct Mod_Int {
    int x;

    Mod_Int() : x(0) {}

    Mod_Int(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

    static int get_mod() {
        return mod;
    }

    Mod_Int &operator+=(const Mod_Int &p) {
        if ((x += p.x) >= mod)
            x -= mod;
        return *this;
    }

    Mod_Int &operator-=(const Mod_Int &p) {
        if ((x += mod - p.x) >= mod)
            x -= mod;
        return *this;
    }

    Mod_Int &operator*=(const Mod_Int &p) {
        x = (int)(1LL * x * p.x % mod);
        return *this;
    }

    Mod_Int &operator/=(const Mod_Int &p) {
        *this *= p.inverse();
        return *this;
    }

    Mod_Int &operator++() {
        return *this += Mod_Int(1);
    }

    Mod_Int operator++(int) {
        Mod_Int tmp = *this;
        ++*this;
        return tmp;
    }

    Mod_Int &operator--() {
        return *this -= Mod_Int(1);
    }

    Mod_Int operator--(int) {
        Mod_Int tmp = *this;
        --*this;
        return tmp;
    }

    Mod_Int operator-() const {
        return Mod_Int(-x);
    }

    Mod_Int operator+(const Mod_Int &p) const {
        return Mod_Int(*this) += p;
    }

    Mod_Int operator-(const Mod_Int &p) const {
        return Mod_Int(*this) -= p;
    }

    Mod_Int operator*(const Mod_Int &p) const {
        return Mod_Int(*this) *= p;
    }

    Mod_Int operator/(const Mod_Int &p) const {
        return Mod_Int(*this) /= p;
    }

    bool operator==(const Mod_Int &p) const {
        return x == p.x;
    }

    bool operator!=(const Mod_Int &p) const {
        return x != p.x;
    }

    Mod_Int inverse() const {
        assert(*this != Mod_Int(0));
        return pow(mod - 2);
    }

    Mod_Int pow(long long k) const {
        Mod_Int now = *this, ret = 1;
        for (; k > 0; k >>= 1, now *= now) {
            if (k & 1)
                ret *= now;
        }
        return ret;
    }

    friend ostream &operator<<(ostream &os, const Mod_Int &p) {
        return os << p.x;
    }

    friend istream &operator>>(istream &is, Mod_Int &p) {
        long long a;
        is >> a;
        p = Mod_Int<mod>(a);
        return is;
    }
};

ll mpow2(ll x, ll n, ll mod) {
    ll ans = 1;
    x %= mod;
    while (n != 0) {
        if (n & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        n = n >> 1;
    }
    ans %= mod;
    return ans;
}

ll modinv2(ll a, ll mod) {
    ll b = mod, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= mod;
    if (u < 0)
        u += mod;
    return u;
}

ll divide_int(ll a, ll b) {
    if (b < 0)
        a = -a, b = -b;
    return (a >= 0 ? a / b : (a - b + 1) / b);
}

// const int MOD = 1000000007;
const int MOD = 998244353;
using mint = Mod_Int<MOD>;

mint mpow(mint x, ll n) {
    bool rev = n < 0;
    n = abs(n);
    mint ans = 1;
    while (n != 0) {
        if (n & 1)
            ans *= x;
        x *= x;
        n = n >> 1;
    }
    return (rev ? ans.inverse() : ans);
}

// ----- library -------
// ----- library -------

int main() {
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(15);

    ll x, a, b;
    cin >> x >> a >> b;
    mint ans = 0, ans2 = 0;
    for (ll i = 1; i * (i + 1) * (i + 2) * (i + 3) <= x; i++) {
        for (ll j = i + 1; i * j * (j + 1) * (j + 2) <= x; j++) {
            ll y = x / i / j, ok = j + 1, ng = 1e9;
            while (abs(ok - ng) > 1) {
                ll mid = ok + ng >> 1;
                (1e18 / i / j / mid / (mid + 1) < 1 || i * j * mid * (mid + 1) > x ? ng : ok) = mid;
            }
            if (a <= i + j && i + j < b)
                ans += ok - j;
            ans += max(0ll, min(ng, b - i) - max(j + 1, a - i));
            ans += max(0ll, min(ng, b - j) - max(j + 1, a - j));
            ll l = (b - i <= 0 ? ng : y / (b - i) + 1), r = (a - i <= 0 ? ng : y / (a - i) + 1);
            ans += max(0ll, min(ng, r) - max(j + 1, l));
            l = (b - j <= 0 ? ng : y / (b - j) + 1), r = (a - j <= 0 ? ng : y / (a - j) + 1);
            ans += max(0ll, min(ng, r) - max(j + 1, l));
            ll oka = 1, nga = ng, okb = 1, ngb = ng;
            while (abs(oka - nga) > 1) {
                ll mid = oka + nga >> 1;
                (mid + y / mid >= a ? oka : nga) = mid;
            }
            while (abs(okb - ngb) > 1) {
                ll mid = okb + ngb >> 1;
                (mid + y / mid >= b ? okb : ngb) = mid;
            }
            ans += max(0ll, nga - max(j + 1, ngb));
        }
    }
    cout << ans * 4 << endl;
}
accuracy: 1
time_ms: 3590
memory_kb: 3452
final_rank: 9

code_snippet: #include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int sqrt_floor(long long X){
  long long ans = max(0, (int) sqrt(X) - 3);
  while ((ans + 1) * (ans + 1) <= X){
    ans++;
  }
  return ans;
}
int main(){
  long long X, L, R;
  cin >> X >> L >> R;
  R--;
  long long ans = 0;
  for (long long i = 1; i * (i + 1) * (i + 2) * (i + 3) <= X; i++){
    for (long long j = i + 1; i * j * (j + 1) * (j + 2) <= X; j++){
      long long Y = X / i / j;
      long long mn = j + 1;
      long long mx = sqrt_floor(Y - 1);
      if (mx * (mx + 1) > Y){
        mx--;
      }
      if (mn <= mx){
        if (L <= i + j && i + j <= R){
          ans += mx - mn + 1;
        }
        ans += max(min(mx, R - i) - max(mn, L - i) + 1, (long long) 0);
        ans += max(min(mx, R - j) - max(mn, L - j) + 1, (long long) 0);
        if (R - i >= j + 2){
          long long lmn = max(L - i, j + 2);
          long long lmx = R - i;
          ans += max(min(mx, Y / lmn) - max(mn, Y / (lmx + 1) + 1) + 1, (long long) 0);
        }
        if (R - j >= j + 2){
          long long lmn = max(L - j, j + 2);
          long long lmx = R - j;
          ans += max(min(mx, Y / lmn) - max(mn, Y / (lmx + 1) + 1) + 1, (long long) 0);
        }
        if (mx + Y / mx <= R){
          long long tv = mx, fv = mn - 1;
          while (tv - fv > 1){
            long long mid = (tv + fv) / 2;
            if (mid + Y / mid <= R){
              tv = mid;
            } else {
              fv = mid;
            }
          }
          ans += mx - fv;
        }
        if (mx + Y / mx < L){
          long long tv = mx, fv = mn - 1;
          while (tv - fv > 1){
            long long mid = (tv + fv) / 2;
            if (mid + Y / mid < L){
              tv = mid;
            } else {
              fv = mid;
            }
          }
          ans -= mx - fv;
        }
      }
    }
  }
  ans %= MOD;
  ans *= 4;
  ans %= MOD;
  cout << ans << endl;
}
accuracy: 1
time_ms: 2800
memory_kb: 3428
final_rank: 4

code_snippet: #include <bits/stdc++.h>
using namespace std;

using Int = long long;

template <class T> void pv(T a, T b) {
  for (T i = a; i != b; ++i) cerr << *i << " ";
  cerr << endl;
}
template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  return os << "(" << p.first << ", " << p.second << ")";
}

// maroon shakyou-modint
using ll=long long;
const uint mod=998244353;
struct mint{
  uint v;
  mint(ll vv=0){s(vv%mod+mod);}
  mint& s(uint vv){
    v=vv<mod?vv:vv-mod;
    return *this;
  }
  mint operator-()const{return mint()-*this;}
  mint&operator+=(mint r){return s(v+r.v);}
  mint&operator-=(mint r){return s(v+mod-r.v);}
  mint&operator*=(mint r){v=(unsigned ll)v*r.v%mod;return *this;}
  mint&operator/=(mint r){return *this*=r.inv();}
  mint operator+(mint r)const{return mint(*this)+=r;}
  mint operator-(mint r)const{return mint(*this)-=r;}
  mint operator*(mint r)const{return mint(*this)*=r;}
  mint operator/(mint r)const{return mint(*this)/=r;}
  mint pow(ll n)const{
    if(n<0)return inv().pow(-n);
    mint res(1),x(*this);
    while(n){
      if(n&1)res*=x;
      x*=x;
      n>>=1;
    }
    return res;
  }
  mint inv()const{return pow(mod-2);}
};

ostream &operator<<(ostream &os, mint a) {
  return os << a.v;
}


mint solve(const Int X, const Int R) {
  mint ans = 0;
  for (Int a = 1; a*(a+1)*(a+2)*(a+3) <= X; ++a) {
    for (Int b = a + 1; a * b*(b+1)*(b+2) <= X; ++b) {
      const Int y = X / (a * b);
      Int lb = b + 1;
      Int ub = sqrt((long double)y);
      for (; ub * (ub + 1) > y; --ub) {}
      
      auto add = [&](Int c0, Int c1) -> void {
// if(X<=30)cerr<<a<<" "<<b<<": ["<<c0<<", "<<c1<<"]"<<endl;
        if (c0 <= c1) {
          ans += (c1 - c0 + 1);
        }
      };
      
      // a+b
      if (a + b < R) add(lb, ub);
      // a+c, b+c
      add(lb, min(ub, R - a - 1));
      add(lb, min(ub, R - b - 1));
      // a+d, b+d
      if (R - a > 0) add(max(lb, y / (R - a) + 1), ub);
      if (R - b > 0) add(max(lb, y / (R - b) + 1), ub);
      // c+d
      Int lo = lb - 1, hi = ub + 1;
      for (; lo + 1 < hi; ) {
        const Int mid = (lo + hi) / 2;
        ((mid + y / mid < R) ? hi : lo) = mid;
      }
      add(hi, ub);
    }
  }
  return ans;
}

int main() {
  Int X, L, R;
  for (; ~scanf("%lld%lld%lld", &X, &L, &R); ) {
    mint ans = 0;
    ans += solve(X, R);
    ans -= solve(X, L);
    ans *= 4;
    printf("%u\n", ans.v);
  }
  return 0;
}
accuracy: 1
time_ms: 2010
memory_kb: 3560
final_rank: 7