結果

問題 No.2176 LRM Question 1
ユーザー coder_So_heycoder_So_hey
提出日時 2023-01-06 22:25:38
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 524 bytes
コンパイル時間 127 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 17,572 KB
最終ジャッジ日時 2024-11-30 18:43:54
合計ジャッジ時間 6,088 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 10 WA * 1 RE * 10 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def fac(n, m):
    if n > 1:
        n *= fac(n - 1, m)
        if n >= m:
            n %= m
        return n
    else:
        return 1

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

if L >= M:
    print(0)
    exit()

facto = 1
index = 2
while facto != 0:
    facto *= fac(index, M)
    if facto >= M:
        facto %= M
    index += 1

ans = 0
for i in range(L, index):
    a = 1
    for j in range(1, i + 1):
        a *= fac(j, M)
        if a >= M:
            a %= M
    ans += a
    if ans >= M:
        ans %= M

print(ans)
0