結果
| 問題 | No.2176 LRM Question 1 | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-07-21 21:05:26 | 
| 言語 | D (dmd 2.109.1) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 44 ms / 2,000 ms | 
| コード長 | 759 bytes | 
| コンパイル時間 | 5,146 ms | 
| コンパイル使用メモリ | 173,088 KB | 
| 実行使用メモリ | 11,892 KB | 
| 最終ジャッジ日時 | 2024-09-21 22:23:06 | 
| 合計ジャッジ時間 | 6,232 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 22 | 
ソースコード
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) {
        product *= factorial[i]; product %= M;
    }
    for (long i = L; i <= min(M, R); i++) {
        product *= factorial[i]; product %= M;
        ans += product; ans %= 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));
    }
}
            
            
            
        