#include using namespace std; #define rep(i,n) for(ll i = 0LL; i < (ll)n; i++) #define FOR(n) for(ll i = 0LL; i < (ll)n; i++) #define repi(i,a,b) for(ll i = (ll)a; i < (ll)b; i++) #define all(x) x.begin(),x.end() //#define mp make_pair #define vi vector #define vvi vector #define vll vector #define vvll vector #define vs vector #define vvs vector #define vc vector #define vvc vector #define pii pair #define pllll pair #define vpii vector> #define vpllll vector> #define vpis vector> #define vplls vector> #define vpsi vector> #define vpsll vector> template void chmax(T &a, const T &b) {a = (a > b? a : b);} template void chmin(T &a, const T &b) {a = (a < b? a : b);} using ll = long long; using ld = long double; using ull = unsigned long long; const ll INF = numeric_limits::max() / 2; const ld pi = acos(-1); const ll mod = 998244353; int dx[] = {-1, 0LL, 1, 0LL, -1, 1, -1, 1}; int dy[] = {0LL, -1, 0LL, 1, -1, -1, 1, 1}; #define int long long void solve() { //1^L*2^(L-1)*...*L+1^(L+1)*2^L*3^(L-1)*...*(L+1)*...* //f(X)= //初項1 //項数X //a_(i+1)=a_i*(i+1)! //S_(n+1)=S_n * ((n+1)! + 1) //s_(n+1)/ //S_1=1 //の時の\sum(a_1...X) //ans = f(R)-f(L) int l, r, m; cin >> l >> r >> m; r = min(r, m); vi fact(r+1, 1); repi(i, 1, r+1) fact[i] = fact[i-1] * i % m; vi s(r+1); s[1] = 1; int now = 1; repi(i, 1, r) { (now *= fact[i+1]) %= m; s[i+1] = (s[i] + now) % m; } if(l > r) cout << 0 << endl; else cout << ((s[r] - s[l-1])%m+m)%m << endl; } //euler tourの点更新、辺更新の追加 signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); solve(); return 0LL; }