結果
問題 | No.2181 LRM Question 2 |
ユーザー | MasKoaTS |
提出日時 | 2022-10-19 20:42:54 |
言語 | PyPy3 (7.3.15) |
結果 |
RE
|
実行時間 | - |
コード長 | 2,369 bytes |
コンパイル時間 | 286 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 383,200 KB |
最終ジャッジ日時 | 2024-06-29 21:42:07 |
合計ジャッジ時間 | 9,972 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 33 ms
52,352 KB |
testcase_01 | RE | - |
testcase_02 | RE | - |
testcase_03 | RE | - |
testcase_04 | AC | 148 ms
110,464 KB |
testcase_05 | AC | 42 ms
61,600 KB |
testcase_06 | RE | - |
testcase_07 | RE | - |
testcase_08 | RE | - |
testcase_09 | RE | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | RE | - |
testcase_13 | RE | - |
testcase_14 | AC | 630 ms
303,892 KB |
testcase_15 | AC | 164 ms
122,384 KB |
testcase_16 | RE | - |
testcase_17 | RE | - |
testcase_18 | RE | - |
testcase_19 | RE | - |
testcase_20 | AC | 603 ms
294,476 KB |
testcase_21 | RE | - |
testcase_22 | AC | 249 ms
150,524 KB |
testcase_23 | RE | - |
testcase_24 | AC | 33 ms
52,992 KB |
testcase_25 | RE | - |
ソースコード
import sys input = sys.stdin.readline class BinomialCoefficient: def __init__(self, mod): self.mod = mod self.prime = self.prime_factorize(mod) self.facs = [] self.invs = [] self.pows = [] self.mods = {} for p, c in self.prime: pc = pow(p, c) fac = [1] * pc inv = [1] * pc for i in range(1, pc): k = i if(i % p == 0): k = 1 fac[i] = fac[i - 1] * k % pc inv[-1] = fac[-1] for i in range(pc - 1, 0, -1): k = i if(i % p == 0): k = 1 inv[i - 1] = inv[i] * k % pc self.facs.append(fac) self.invs.append(inv) pw = [1] while(pw[-1] * p != pc): pw.append(pw[-1] * p) self.pows.append(pw) r = [0] * len(self.prime) pcs = [pow(p, c) for p, c in self.prime] for i in range(1, mod): for j, pc in enumerate(pcs): r[j] += 1 if(r[j] >= pc): r[j] -= pc self.mods[tuple(r)] = i def prime_factorize(self, n): prime = [] f = 2 while(f * f <= n): if(n % f == 0): n //= f cnt = 1 while(n % f == 0): n //= f cnt += 1 prime.append((f, cnt)) f += 1 if(n != 1): prime.append((n, 1)) return prime def inv_gcd(self, n, m): n %= m if(n == 0): return m, 0 s, t, m0, m1 = m, n, 0, 1 while(t): u = s // t s -= t * u m0 -= m1 * u m0, m1, s, t = m1, m0, t, s if(m0 < 0): m0 += m // s return s, m0 def inv_mod(self, n, m): g, im = self.inv_gcd(n, m) return im def calc_e(self, n, k, r, p): e = 0 while(n): n //= p e += n while(k): k //= p e -= k while(r): r //= p e -= r return e def lucas(self, n, k, p, c, i): pw = self.pows[i] fac = self.facs[i] inv = self.invs[i] r = n - k pc = pow(p, c) e = self.calc_e(n, k, r, p) if(e >= len(pw)): return 0 ret = pw[e] if((p != 2 or c < 3) and (self.calc_e(n // pw[-1], k // pw[-1], r // pw[-1], p) & 1)): ret *= -1 while(n): ret *= fac[n % pc] * inv[k % pc] * inv[r % pc] ret %= pc n //= p k //= p r //= p return ret def __call__(self, n, k): if(k < 0 or k > n): return 0 if(k == 0 or k == n): return 1 r = [self.lucas(n, k, p, c, i) for i, (p, c) in enumerate(self.prime)] return self.mods[tuple(r)] """ Main Code """ l, r, m = map(int, input().split()) nCk = BinomialCoefficient(m) ans = 0 for i in range(l, r + 1): ans += nCk(2 * i, i) + m - 2 ans %= m print(ans)