結果

問題 No.1809 Divide NCK
ユーザー brthyyjp
提出日時 2022-01-14 21:39:28
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 55 ms / 2,000 ms
コード長 607 bytes
コンパイル時間 374 ms
コンパイル使用メモリ 82,204 KB
実行使用メモリ 57,984 KB
最終ジャッジ日時 2024-11-20 08:43:15
合計ジャッジ時間 3,229 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
def factorize(n):
    d = {}
    temp = int(math.sqrt(n))+1
    for i in range(2, temp):
        while n%i== 0:
            n //= i
            if i in d:
                d[i] += 1
            else:
                d[i] = 1
    if d == {}:
        d[n] = 1
    else:
        if n in d:
            d[n] += 1
        elif n != 1:
            d[n] =1
    return d

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

D = factorize(m)
ans = 10**18
for p, q in D.items():
    x = p
    cnt = 0
    while x <= n:
        cnt += n//x-(n-k)//x
        cnt -= k//x
        x *= p
    ans = min(ans, cnt//q)
print(ans)
0