結果

問題 No.2176 LRM Question 1
ユーザー FromBooskaFromBooska
提出日時 2023-06-02 18:41:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 705 ms / 2,000 ms
コード長 987 bytes
コンパイル時間 276 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 257,884 KB
最終ジャッジ日時 2023-08-28 02:24:52
合計ジャッジ時間 10,933 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,212 KB
testcase_01 AC 76 ms
71,068 KB
testcase_02 AC 705 ms
257,676 KB
testcase_03 AC 76 ms
71,420 KB
testcase_04 AC 680 ms
257,792 KB
testcase_05 AC 100 ms
82,632 KB
testcase_06 AC 85 ms
76,684 KB
testcase_07 AC 97 ms
80,716 KB
testcase_08 AC 688 ms
257,788 KB
testcase_09 AC 662 ms
254,988 KB
testcase_10 AC 583 ms
257,120 KB
testcase_11 AC 75 ms
71,180 KB
testcase_12 AC 75 ms
71,292 KB
testcase_13 AC 688 ms
257,884 KB
testcase_14 AC 683 ms
257,820 KB
testcase_15 AC 546 ms
256,604 KB
testcase_16 AC 482 ms
217,988 KB
testcase_17 AC 92 ms
77,740 KB
testcase_18 AC 632 ms
253,628 KB
testcase_19 AC 442 ms
202,588 KB
testcase_20 AC 195 ms
117,484 KB
testcase_21 AC 334 ms
163,560 KB
testcase_22 AC 103 ms
80,680 KB
testcase_23 AC 300 ms
153,444 KB
testcase_24 AC 326 ms
164,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# M<10**6で、L, R < 10**18
# しかしMを超えれば余りはゼロになる
# つまり計算はMまででいい

L, R, M = map(int, input().split())
mod = M
N = M

# nCrメモ化パッケージ
factorial = [1] #0分
inverse = [1] #0分
for i in range(1, N+1):
    factorial.append(factorial[-1]*i%mod)
    inverse.append(pow(factorial[-1], mod-2, mod))

# パッケージだからあるけど今回は使わないnCr_fast
def nCr_fast(N, R, MOD):
    if N < R or R < 0:
        return 0
    elif R == 0 or R == N:
        return 1
    return factorial[N]*inverse[R]*inverse[N-R]%MOD

factorial_factorial = [1]
for i in range(1, N+1):
    factorial_factorial.append(factorial_factorial[-1]*factorial[i]%mod)

if L >= M:
    ans = 0
elif L < M and R >= M:
    ans = 0
    for i in range(L, M+1):
        ans += factorial_factorial[i]
        ans %= mod
elif L < M and R < M:
    ans = 0
    for i in range(L, R+1):
        ans += factorial_factorial[i] 
        ans %= mod
print(ans)
0