結果

問題 No.2176 LRM Question 1
ユーザー ineedyourlovepineedyourlovep
提出日時 2023-01-06 21:50:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 2,777 bytes
コンパイル時間 2,113 ms
コンパイル使用メモリ 205,476 KB
実行使用メモリ 8,276 KB
最終ジャッジ日時 2023-08-20 14:55:43
合計ジャッジ時間 3,589 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 50 ms
7,732 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 43 ms
7,780 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 51 ms
7,680 KB
testcase_15 AC 42 ms
7,700 KB
testcase_16 AC 35 ms
8,276 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 23 ms
5,120 KB
testcase_22 AC 4 ms
4,376 KB
testcase_23 AC 20 ms
5,068 KB
testcase_24 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < (n); i++)
#define drep(i, a, n) for(int i = (n)-1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 1000000007;
//const int mod = 998244353;

int mod = 1000000007;

//MINT
struct mint {
  unsigned x;
  mint(): x(0) {}
  mint(ll x):x((x%mod+mod)%mod) {}
  mint operator-() const { return mint(0) - *this;}
  mint operator~() const { return mint(1) / *this;}
  mint& operator+=(const mint& a) { if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a) { if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a) { x=(unsigned long long)x*a.x%mod; return *this;}
  mint& operator/=(const mint& a) { x=(unsigned long long)x*a.pow(mod-2).x%mod; return *this;}
  mint operator+(const mint& a) const { return mint(*this) += a;}
  mint operator-(const mint& a) const { return mint(*this) -= a;}
  mint operator*(const mint& a) const { return mint(*this) *= a;}
  mint operator/(const mint& a) const { return mint(*this) /= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint res = pow(t>>1);
    res *= res;
    return (t&1)?res*x:res;
  }
  bool operator<(const mint& a) const { return x < a.x;}
  bool operator==(const mint& a) const { return x == a.x;}
  bool operator!=(const mint& a) const { return x != a.x;}
};
mint ex(mint x, ll t) { return x.pow(t);}
istream& operator>>(istream& i, mint& a) { unsigned long long t; i>>t; a=mint(t); return i;}
ostream& operator<<(ostream& o, const mint& a) { return o<<a.x;}

struct modinv{
    int n;
    vector<mint> d;
    modinv(): n(2), d({0, 1}) {};
    mint operator()(int i){ while(n <= i){ d.push_back(-d[mod%n]*(mod/n)); n++;} return d[i];}
    mint operator[](int i) const { return d[i];}
}invs;
struct modfact{
    int n;
    vector<mint> d;
    modfact(): n(2), d({1, 1}) {}
    mint operator()(int i) { while(n <= i){ d.push_back(d.back()*n); n++;} return d[i];}
    mint operator[](int i) const { return d[i];}
}facs;
struct modfactinv{
    int n;
    vector<mint> d;
    modfactinv(): n(2), d({1, 1}) {}
    mint operator()(int i) { while(n <= i){ d.push_back(d.back()*invs(n)); n++;} return d[i];}
    mint operator[](int i) const { return d[i];}
}ifacs;
mint comb(int a, int b){
    if(a < b || b < 0) return 0;
    return facs(a)*ifacs(b)*ifacs(a-b);
}

int main()
{
  ll l, r, m;
  cin >> l >> r >> m;
  mod = (int)m;
  if (l >= m) {
    cout << 0 << endl;
    return 0;
  }
  mint ans = 1;
  rep(i, 1, l+1) {
    ans = ans*facs(i);
  }
  mint res = ans;
  for (ll i = l+1; i <= min(r, m); i++) {
    res += ans*facs((int)i);
    ans *= facs((int)i);
  }
  cout << res << endl;
  return 0;
}
0