#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include template struct DSU { std::vector f, siz; DSU(int n) : f(n), siz(n, 1) { std::iota(f.begin(), f.end(), 0); } T leader(T x) { while (x != f[x]) x = f[x] = f[f[x]]; return x; } bool same(T x, T y) { return leader(x) == leader(y); } bool merge(T x, T y) { x = leader(x); y = leader(y); if (x == y) return false; siz[x] += siz[y]; f[y] = x; return true; } T size(int x) { return siz[leader(x)]; } }; std::pair, std::vector> get_prime_factor_with_kinds( long long n) { std::vector prime_factors; std::vector cnt; // number of i_th factor for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) { prime_factors.push_back(i); cnt.push_back(0); while (n % i == 0) n /= i, cnt[(int)prime_factors.size() - 1]++; } } if (n > 1) prime_factors.push_back(n), cnt.push_back(1); assert(prime_factors.size() == cnt.size()); return {prime_factors, cnt}; } void solve() { long long l, r, m; std::cin >> l >> r >> m; if (l >= m) { std::cout << 0 << '\n'; return; } r = std::min(r, m - 1); long long f = 1, g = 1; for (long long i = 2; i < l; i++) { f = f * i % m; g = g * f % m; } long long ans = 0; for (long long i = l; i <= r; i++) { f = f * i % m; g = g * f % m; ans += g; ans %= m; } std::cout << ans << '\n'; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); int t = 1; // std::cin >> t; while (t--) solve(); // solve(); return 0; }