#include using namespace std; using ll = long long; ll calc(ll N, ll M) { if (N >= M) { return calc(M - 1, M); } if (N == 0) { return 0; } ll ka = 1, pr = 1, sum = 0; for (ll i = 1; i <= N; i ++) { ka = (ka * i) % M; pr = (pr * i) % M; sum = (sum + pr) % M; } return sum; } int main () { ll l, r, m; cin >> l >> r >> m; cout << ((calc(r, m) - calc(l - 1, m) + m) % m) << endl; }