結果

問題 No.1809 Divide NCK
ユーザー lam6er
提出日時 2025-03-20 21:15:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 677 bytes
コンパイル時間 160 ms
コンパイル使用メモリ 82,776 KB
実行使用メモリ 60,276 KB
最終ジャッジ日時 2025-03-20 21:16:31
合計ジャッジ時間 3,360 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

def count_p_in_factorial(n, p):
    count = 0
    while n > 0:
        n = n // p
        count += n
    return count

N, K, M = map(int, input().split())

# Factorize M
factors = {}
m = M
i = 2
while i * i <= m:
    while m % i == 0:
        factors[i] = factors.get(i, 0) + 1
        m = m // i
    i += 1
if m > 1:
    factors[m] = 1

min_x = float('inf')

for p, e in factors.items():
    cnt_n = count_p_in_factorial(N, p)
    cnt_k = count_p_in_factorial(K, p)
    nk = N - K
    cnt_nk = count_p_in_factorial(nk, p) if nk != 0 else 0
    v_p = cnt_n - cnt_k - cnt_nk
    x_p = v_p // e
    if x_p < min_x:
        min_x = x_p

ans = min_x if min_x >= 0 else 0
print(ans)
0