結果
問題 | No.2120 場合の数の下8桁 |
ユーザー | mkawa2 |
提出日時 | 2022-11-07 22:24:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,511 ms / 2,000 ms |
コード長 | 2,949 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 81,868 KB |
実行使用メモリ | 257,868 KB |
最終ジャッジ日時 | 2024-07-21 05:35:06 |
合計ジャッジ時間 | 5,978 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 72 ms
68,964 KB |
testcase_01 | AC | 66 ms
68,484 KB |
testcase_02 | AC | 64 ms
67,628 KB |
testcase_03 | AC | 64 ms
68,040 KB |
testcase_04 | AC | 65 ms
68,240 KB |
testcase_05 | AC | 66 ms
68,764 KB |
testcase_06 | AC | 71 ms
68,300 KB |
testcase_07 | AC | 64 ms
68,052 KB |
testcase_08 | AC | 63 ms
67,856 KB |
testcase_09 | AC | 65 ms
68,496 KB |
testcase_10 | AC | 66 ms
67,492 KB |
testcase_11 | AC | 65 ms
67,428 KB |
testcase_12 | AC | 67 ms
68,388 KB |
testcase_13 | AC | 110 ms
79,940 KB |
testcase_14 | AC | 129 ms
84,604 KB |
testcase_15 | AC | 713 ms
256,100 KB |
testcase_16 | AC | 97 ms
78,284 KB |
testcase_17 | AC | 1,511 ms
257,040 KB |
testcase_18 | AC | 62 ms
68,500 KB |
testcase_19 | AC | 1,496 ms
257,868 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 import typing def inv_gcd(a, b): a %= b if a == 0: return b, 0 s, t = b, a m0, m1 = 0, 1 while t: u = s//t s -= t*u m0 -= m1*u s, t = t, s m0, m1 = m1, m0 if m0 < 0: m0 += b//s return s, m0 # 複数の「mで割ったらr余る」という条件を満たすxをmod zで返す # 返り値 x,z(解なしの場合は0,0) def crt(r: typing.List[int], m: typing.List[int]) -> typing.Tuple[int, int]: assert len(r) == len(m) n = len(r) r0, m0 = 0, 1 for i in range(n): assert 1 <= m[i] r1 = r[i]%m[i] m1 = m[i] if m0 < m1: r0, r1 = r1, r0 m0, m1 = m1, m0 if m0%m1 == 0: if r0%m1 != r1: return 0, 0 continue g, im = inv_gcd(m0, m1) u1 = m1//g if (r1-r0)%g: return 0, 0 x = (r1-r0)//g%u1*im%u1 r0 += x*m0 m0 *= u1 if r0 < 0: r0 += m0 return r0, m0 def inv(a, p, e): m = p**e a0 = a res = {1: 1} aa = [a] while aa: a = aa.pop() if m%a%p: b = m%a if b in res: res[a] = m-m//a*res[b]%m else: aa.append(a) aa.append(b) else: b = a-m%a if b in res: res[a] = res[b]*(m//a+1)%m else: aa.append(a) aa.append(b) return res[a0] def trim(a): x = y = 0 while a & 1 == 0: a >>= 1 x += 1 while a%5 == 0: a //= 5 y += 1 return a, x, y m = II() n = II() if m < n: print("0"*8) exit() if m-n < n: n = m-n # if n==0: # print(1) # exit() aa, bb = [], [] cnt = [0, 0] for i in range(n): a, c2, c5 = trim(m-i) cnt[0] += c2 cnt[1] += c5 aa.append(a) b, c2, c5 = trim(i+1) bb.append(b) cnt[0] -= c2 cnt[1] -= c5 rr = [] for p in [2, 5]: m = p**8 x = y = 1 for a in aa: x = x*a%m c2, c5 = cnt x = x*pow(2, c2, m)%m*pow(5, c5, m)%m for b in bb: y = y*b%m y = inv(y, p, 8) rr.append(x*y%m) ans, _ = crt(rr, [2**8, 5**8]) ans = str(ans).zfill(8) print(ans)