結果

問題 No.2176 LRM Question 1
ユーザー InIn
提出日時 2023-07-21 21:02:33
言語 D
(dmd 2.106.1)
結果
WA  
実行時間 -
コード長 763 bytes
コンパイル時間 4,066 ms
コンパイル使用メモリ 163,148 KB
実行使用メモリ 12,236 KB
最終ジャッジ日時 2023-10-21 20:52:23
合計ジャッジ時間 6,892 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 42 ms
10,436 KB
testcase_03 AC 1 ms
4,348 KB
testcase_04 WA -
testcase_05 AC 3 ms
4,756 KB
testcase_06 WA -
testcase_07 AC 3 ms
4,756 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 36 ms
10,700 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 43 ms
10,436 KB
testcase_15 AC 34 ms
9,908 KB
testcase_16 AC 28 ms
8,384 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 1 ms
4,348 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 18 ms
5,548 KB
testcase_22 AC 3 ms
4,756 KB
testcase_23 AC 16 ms
5,280 KB
testcase_24 AC 1 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std;

void main () {
    long L, R;
    int M;
    readln.read(L, R, M);
    solve(L, R, M);
}

void solve (long L, long R, int M) {
    if (M < L) {
        writeln(0);
        return;
    }

    long[] factorial = new long[](M+1);
    factorial[0] = 1 % M;
    foreach (i; 1..M+1) {
        factorial[i] = i*factorial[i-1] % M;
    }

    long ans = 0;
    long product = 1;
    foreach (i; 1..L+1) {
        product *= factorial[i]; product %= M;
    }

    for (long i = L+1; i <= min(M, R); i++) {
        ans += product; ans %= M;
        product *= factorial[i]; product %= M;
    }

    writeln(ans);
}

void read(T...)(string S, ref T args) {
    auto buf = S.split;
    foreach (i, ref arg; args) {
        arg = buf[i].to!(typeof(arg));
    }
}
0