#include using namespace std; using ll = long long; struct BinomialCoefficient { ll mod = 2; vector > prime = {}; vector > facs = {}; vector > invs = {}; vector > pows = {}; vector factinvs = {}; static void swap(ll& a, ll& b) { ll tmp = a; a = b; b = tmp; } static ll pow(ll a, ll n) { ll ret = 1; while (n) { if (n & 1) { ret *= a; } a *= a; n >>= 1; } return ret; } static vector > primeFactorize(ll n) { vector > ret = {}; ll cnt = 0; for (cnt; (n & 1) == 0; ++cnt) { n >>= 1; } if (cnt > 0) { ret.push_back({ 2,cnt }); } for (ll f = 3; f * f <= n; f += 2) { cnt = 0; for (cnt; n % f == 0; ++cnt) { n /= f; } if (cnt > 0) { ret.push_back({ f,cnt }); } } if (n > 1) { ret.push_back({ n,1 }); } return ret; } BinomialCoefficient() { } BinomialCoefficient(ll mod) { this->mod = mod; prime = primeFactorize(mod); for (pair& pa : prime) { ll p = pa.first, c = pa.second; ll pc = pow(p, c); vector fac(pc, 1); vector inv(pc, 1); for (ll i = 1; i < pc; ++i) { ll k = (i % p) ? i : 1; fac[i] = fac[i - 1] * k % pc; } inv[inv.size() - 1] = fac[inv.size() - 1]; for (ll i = pc - 1; i > 0; --i) { ll k = (i % p) ? i : 1; inv[i - 1] = inv[i] * k % pc; } facs.push_back(fac); invs.push_back(inv); vector pw = { 1 }; while (pw[pw.size() - 1] * p != pc) { pw.push_back(pw[pw.size() - 1] * p); } pows.push_back(pw); } } pair crt(vector& r, vector& m) { ll n = r.size(); ll r0 = 0, m0 = 1; for (int i = 0; i < r.size(); ++i) { ll a = r[i], b = m[i]; ll r1 = a % b, m1 = b; if (m0 < m1) { swap(r0, r1); swap(m0, m1); } if (m0 % m1 == 0) { if (r0 % m1 != r1) { return { 0, 0 }; } continue; } pair pa = inv_gcd(m0, m1); ll g = pa.first, im = pa.second; ll u1 = m1 / g; if ((r1 - r0) % g) { return { 0,0 }; } ll x = (r1 - r0) / g * im % u1; r0 += x * m0; m0 *= u1; if (r0 < 0) { r0 += m0; } } return { r0,m0 }; } pair inv_gcd(ll n, ll m) { n %= m; if (n == 0) { return { m, 0 }; } ll s = m, t = n, m0 = 0, m1 = 1; while (t) { ll u = s / t; s -= t * u; m0 -= m1 * u; swap(m0, m1); swap(s, t); } if (m0 < 0) { m0 += m / s; } return { s, m0 }; } ll inv_mod(ll n, ll m) { pair pa = inv_gcd(n, m); return pa.second; } ll calc_e(ll n, ll k, ll r, ll p) { ll e = 0; while (n) { n /= p; e += n; } while (k) { k /= p; e -= k; } while (r) { r /= p; e -= r; } return e; } ll lucas(ll n, ll k, ll p, ll c, ll i) { vector& pw = pows[i]; vector& fac = facs[i]; vector& inv = invs[i]; ll r = n - k, pc = pow(p, c); ll e = calc_e(n, k, r, p); if (e >= pw.size()) { return 0; } ll ret = pw[e]; if ((p != 2 or c < 3) and (calc_e(n / pw[pw.size() - 1], k / pw[pw.size() - 1], r / pw[pw.size() - 1], p) & 1)) { ret = -ret; } while (n) { ret *= fac[n % pc] * inv[k % pc] % pc * inv[r % pc] % pc; ret %= pc; n /= p; k /= p; r /= p; } return ret; } ll calc(ll n, ll k) { if (k < 0 or k > n) { return 0; } if (k == 0 or k == n) { return 1; } vector r = {}, m = {}; for (int i = 0; i < prime.size(); ++i) { pair pa = prime[i]; ll p = pa.first, c = pa.second; r.push_back(lucas(n, k, p, c, i)); m.push_back(pow(p, c)); } pair pa = crt(r, m); return pa.first; } }; /* * Main Code */ int main(void) { ll l, r, m; cin >> l >> r >> m; BinomialCoefficient nCk(m); ll ans = 0; for (ll i = l; i < r + 1; ++i) { ans += nCk.calc(i << 1, i) - 2; ans %= m; } cout << ans << endl; return 0; }