結果

問題 No.1809 Divide NCK
ユーザー lloyz
提出日時 2022-01-14 23:36:16
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 336 ms / 2,000 ms
コード長 629 bytes
コンパイル時間 753 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-11-20 15:20:44
合計ジャッジ時間 3,970 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k, m = map(int, input().split())

Prime = []
f = 2
while f * f <= m:
    if m % f == 0:
        cnt = 1
        m //= f
        while m % f == 0:
            m //= f
            cnt += 1
        Prime.append((f, cnt))
    f += 1
if m != 1:
    Prime.append((m, 1))

def legendre(n, k, p, cnt):
    r = n - k
    ans = 0
    while n:
        n //= p
        ans += n
    while k:
        k //= p
        ans -= k
    while r:
        r //= p
        ans -= r
    return ans // cnt

ans = 10**18
for prime, cnt in Prime:
    cnt = legendre(n, k, prime, cnt)
    ans = min(ans, cnt)
print(ans)
0