結果

問題 No.2176 LRM Question 1
ユーザー tsugutsugutsugutsugu
提出日時 2023-03-19 00:51:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 1,513 ms
コンパイル使用メモリ 169,068 KB
実行使用メモリ 18,932 KB
最終ジャッジ日時 2023-10-18 17:39:28
合計ジャッジ時間 3,435 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 56 ms
18,932 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 40 ms
18,932 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 4 ms
4,348 KB
testcase_08 AC 40 ms
18,932 KB
testcase_09 AC 38 ms
18,404 KB
testcase_10 AC 47 ms
16,360 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 40 ms
18,932 KB
testcase_14 AC 57 ms
18,932 KB
testcase_15 AC 44 ms
15,568 KB
testcase_16 AC 37 ms
13,260 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 36 ms
17,348 KB
testcase_19 AC 27 ms
12,800 KB
testcase_20 AC 11 ms
6,336 KB
testcase_21 AC 25 ms
9,436 KB
testcase_22 AC 4 ms
4,348 KB
testcase_23 AC 21 ms
8,644 KB
testcase_24 AC 19 ms
9,704 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    long long l, r, m;
    cin >> l >> r >> m;
    if (m == 1) {
        cout << 0 << '\n';
        return 0;
    }
    vector<long long> fac(m, 1);
    for (int i = 2; i < m; i++) {
        fac[i] = fac[i - 1] * i;
        fac[i] %= m;
    }
    vector<long long> pre(m, 1);
    for (int i = 2; i < m; i++) {
        pre[i] = pre[i - 1] * fac[i];
        pre[i] %= m;
    }
    if (l >= m) {
        cout << 0 << '\n';
    } else {
        r = min(r, m - 1);
        long long ans = 0;
        for (long long i = l; i <= r; i++) {
            ans += pre[i];
            ans %= m;
        }
        cout << ans << '\n';
    }
}
0