結果

問題 No.2176 LRM Question 1
ユーザー kztasakztasa
提出日時 2023-01-06 21:44:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 3,004 bytes
コンパイル時間 5,826 ms
コンパイル使用メモリ 231,800 KB
実行使用メモリ 18,796 KB
最終ジャッジ日時 2023-08-20 14:48:37
合計ジャッジ時間 5,085 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 50 ms
18,612 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 34 ms
18,536 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 35 ms
18,796 KB
testcase_09 AC 34 ms
18,376 KB
testcase_10 AC 40 ms
16,392 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 50 ms
18,572 KB
testcase_15 AC 39 ms
15,568 KB
testcase_16 AC 33 ms
13,100 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 21 ms
9,468 KB
testcase_22 AC 3 ms
4,376 KB
testcase_23 AC 18 ms
8,712 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h> 
#include <atcoder/all>
#define pub push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (ll i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (ll i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
using namespace atcoder;
using ll = long long;
using Pll = pair<ll, ll>;
using mint = modint998244353;
using mint2 = modint1000000007;

constexpr long long INF = (1LL << 60);

template <typename T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;  // aをbで更新
        return true;
    }
    return false;
}

template <typename T>
T square(T x) {
    return x * x;
}

std::string zfill(int n, const int width)
{
    std::stringstream ss;
    ss << std::setw(width) << std::setfill('0') << n;
    return ss.str();
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

template<typename T = int>
std::map<T, ll> factorize(T n) {
    std::map<T, ll> factor_map;
    for (T i = 2; i * i <= n; i++) {
        while (!(n % i)) {
            factor_map[i]++; n /= i;
        }
    }
    if (n > 1) factor_map[n]++;
    return factor_map;
}


/*  divisor(n)
    入力:整数 n
    出力:nのすべての約数
    計算量:O(√n)
*/
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}


int main(void) {
    ll L, R, M; cin >> L >> R >> M;
    if (L >= M) {
        cout << 0 << endl;
        return 0;
    }
    else {
        //kaijou no mod
        vector<ll> k(M + 1);
        k[1] = 1 % M;
        rep(i, M) {
            if (i == 0) {
                continue;
            }
            else {
                k[i + 1] = k[i] * (i + 1);
                k[i + 1] %= M;
            }
        }
        //1!2!…i!%M
        vector<ll> k2(M + 1);
        rep(i, M) {
            if (i == 0) {
                k2[i + 1] = k[1];
            }
            else {
                k2[i + 1] = k2[i] * k[i + 1];
                k2[i + 1] %= M;
            }
        }
        ll ans = 0;
        for (ll i = L; i <= min(R,M); i++) {
            ans += k2[i];
            ans %= M;
        }
        cout << ans << endl;
    }
}








0