#include using namespace std; #include using namespace atcoder; using mint = modint; typedef long long ll; #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() const int MAX = 1e9; const int MIN = -1*1e9; const ll MAXLL = 1e18; const ll MINLL = -1*1e18; vector DP(1000010); mint Solve(ll N, ll M) { N = min(N,M-1); return DP[N]; } int main() { ll L,R,M; cin >> L >> R >> M; modint::set_mod(M); mint P = 1, Sum = 1, Ans = 1; DP[1] = 1; for(int i = 2; i <= 1000000; i++) { P *= i; Sum *= P; Ans += Sum; DP[i] = Ans; } cout << (Solve(R,M)-Solve(L-1,M)).val() << endl; return 0; }