#pragma GCC optimize("Ofast") #include using namespace std; typedef long long int ll; ll mod_pow(ll a,ll b,ll mod){ a%=mod; if(b==0)return 1; if(b==1)return a; ll res=mod_pow(a,b/2,mod)%mod; res*=res; res%=mod; if(b%2)res*=a; return res%mod; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); ll L,R,M; cin >> L >> R >> M; ll res = 0; ll cur = 1; ll u = 1; for (ll i = 1; i < L; ++i) { if(L >= M) break; u *= i; u %= M; } for (ll i = L; i <= R; ++i) { if(i >= M) break; u *= i; u %= M; if(i == L){ for (int j = 1; j <= L; ++j) { cur *= mod_pow(j,L+1-j,M); cur %= M; } } else{ cur *= u; cur %= M; } res += cur; } cout << res%M << endl; }