#include using namespace std; #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #define rep(i,n) for (int i=0;i<(long long)(n);i++) #define all(v) v.begin(),v.end() using ll=long long; using pll=pair; using tll=tuple; const ll INF=(1ll<<60); template void chmin(T &a,T b){ if(a>b){ a=b; } } template void chmax(T &a,T b){ if(a> l >> r >> m; vector f(m+1); f[0]=1; f[1]=1; rep(i,m){ if(i<1) continue; f[i+1]=f[i]%m*(i+1)%m; } vector ff(m+2,1); rep(i,m+1) ff[i+1]=ff[i]%m*f[i]%m; ll ans=0; for(ll i=l;i<=min(m+1,r);i++){ ans+=ff[i+1]; ans%=m; } cout << ans << endl; }