1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <bits/stdc++.h>


using namespace std;


const int MOD = 998244353;

int add(int x, int y) {
    x += y;
    if (x >= MOD) {
        x -= MOD;
    }

    return x;
}

int expo(int a, long long n, int mod) {
    int ans = 1;

    while (n) {
        if (n & 1LL) {
            ans = ((long long) ans * a) % mod;
        }

        n >>= 1;
        a = ((long long) a * a) % mod;
    }

    return ans;
}

int revMod(int a, int mod) {
    return expo(a, mod - 2, mod);
}

pair <int,int> join(int x, bool bx, int y, bool by) {
    return {
        x + y - (bx && by),
        bx && by ? 0 : bx
    };
}

vector <int> countUnrooted(int n, int c) {
    vector <vector<int>> dpRooted(n + 1, vector <int> (2, 0));
    dpRooted[1][1] = c;

    auto getCoefs = [&](int i, int v) {
        vector <int> coefs = {1};

        int coef = 1;
        for (int j = 1; (j - 1) * i <= n; j++) {
            coef = ((long long) coef * (v - 1 + j)) % MOD;
            coef = ((long long) coef * revMod(j, MOD)) % MOD;
            coefs.push_back(coef);
        }

        return coefs;
    };

    for (int i = 1; i <= n; i++) {
        int v0 = dpRooted[i][0], v1 = dpRooted[i][1];
        int v2 = (v0 + (long long) v1 * c) % MOD;

        auto coefsFirst = getCoefs(i, v1);
        auto coefsSecond = getCoefs(i, v2);

        for (int j = n; j >= i + 1; j--) for (int m = 1; m * i <= j; m++) {
            int sum = add(dpRooted[j - m * i][0], dpRooted[j - m * i + 1][1]);
            dpRooted[j][0] = (dpRooted[j][0] + (long long) coefsFirst[m] * sum) % MOD;
        }

        dpRooted[i][0] = v2;

        for (int j = n; j >= i + 1; j--) for (int m = 1; m * i < j; m++) {
            for (int b = 0; b <= 1; b++) {
                dpRooted[j][b] = (dpRooted[j][b] + (long long) coefsSecond[m] * dpRooted[j - m * i][b]) % MOD;
            }
        }
    }

    vector <vector<int>> dpUnrooted = dpRooted;
    for (int i = 1; i <= n; i++) for (int bi = 0; bi <= 1; bi++) {
        for (int j = i; j <= n; j++) for (int bj = 0; bj <= 1; bj++) {
            if (i == j && bi > bj) {
                continue;
            }

            int numWays;
            if (i != j || bi != bj) {
                numWays = ((long long) dpRooted[i][bi] * dpRooted[j][bj]) % MOD;
            } else {
                numWays = ((long long) dpRooted[i][bi] * (dpRooted[i][bi] - 1) / 2) % MOD;
            }

            auto [k, bk] = join(i, bi, j, bj);
            if (k <= n) {
                dpUnrooted[k][bk] = add(dpUnrooted[k][bk], MOD - numWays);
            }
        }
    }

    vector <int> cntUnrooted(n + 1, 0);
    for (int i = 1; i <= n; i++) for (int bi = 0; bi <= 1; bi++) {
        cntUnrooted[i] = add(cntUnrooted[i], dpUnrooted[i][bi]);
    }

    return cntUnrooted;
}

int solve(int l, int r, int c) {
    auto cntUnrooted = countUnrooted(r, c);

    int ans = 0;
    for (int i = l; i <= r; i++) {
        ans = add(ans, cntUnrooted[i]);
    }

    return ans;
}

int main() {
    ios_base::sync_with_stdio(false);

    int l, r, c;
    cin >> l >> r >> c;

    cout << solve(l, r, c);

    return 0;
}