結果

問題 No.1809 Divide NCK
ユーザー 👑 KazunKazun
提出日時 2022-01-14 21:31:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 41 ms / 2,000 ms
コード長 1,374 bytes
コンパイル時間 317 ms
コンパイル使用メモリ 82,732 KB
実行使用メモリ 58,972 KB
最終ジャッジ日時 2024-04-30 12:52:34
合計ジャッジ時間 2,714 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,572 KB
testcase_01 AC 34 ms
53,072 KB
testcase_02 AC 34 ms
52,256 KB
testcase_03 AC 33 ms
53,444 KB
testcase_04 AC 33 ms
52,484 KB
testcase_05 AC 33 ms
53,692 KB
testcase_06 AC 33 ms
52,500 KB
testcase_07 AC 32 ms
52,200 KB
testcase_08 AC 31 ms
53,028 KB
testcase_09 AC 32 ms
52,192 KB
testcase_10 AC 32 ms
52,564 KB
testcase_11 AC 32 ms
53,356 KB
testcase_12 AC 33 ms
53,204 KB
testcase_13 AC 36 ms
58,092 KB
testcase_14 AC 34 ms
53,624 KB
testcase_15 AC 33 ms
52,416 KB
testcase_16 AC 39 ms
58,972 KB
testcase_17 AC 36 ms
57,660 KB
testcase_18 AC 41 ms
58,732 KB
testcase_19 AC 41 ms
58,716 KB
testcase_20 AC 34 ms
53,120 KB
testcase_21 AC 33 ms
53,608 KB
testcase_22 AC 33 ms
53,856 KB
testcase_23 AC 34 ms
52,888 KB
testcase_24 AC 32 ms
52,284 KB
testcase_25 AC 32 ms
52,816 KB
testcase_26 AC 32 ms
52,604 KB
testcase_27 AC 32 ms
52,392 KB
testcase_28 AC 32 ms
53,068 KB
testcase_29 AC 38 ms
58,096 KB
testcase_30 AC 36 ms
57,804 KB
testcase_31 AC 33 ms
52,744 KB
testcase_32 AC 33 ms
52,944 KB
testcase_33 AC 36 ms
57,664 KB
testcase_34 AC 36 ms
58,392 KB
testcase_35 AC 36 ms
58,176 KB
testcase_36 AC 35 ms
58,024 KB
testcase_37 AC 35 ms
52,456 KB
testcase_38 AC 34 ms
53,408 KB
testcase_39 AC 34 ms
53,716 KB
testcase_40 AC 35 ms
52,464 KB
testcase_41 AC 35 ms
52,888 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#素因数分解
def Prime_Factorization(N):
    if N==0:
        return [[0,1]]

    if N<0:
        R=[[-1,1]]
    else:
        R=[]

    N=abs(N)

    if N&1==0:
        C=0
        while N&1==0:
            N>>=1
            C+=1
        R.append([2,C])

    if N%3==0:
        C=0
        while N%3==0:
            N//=3
            C+=1
        R.append([3,C])

    k=5
    Flag=0
    while k*k<=N:
        if N%k==0:
            C=0
            while N%k==0:
                C+=1
                N//=k
            R.append([k,C])
        k+=2+2*Flag
        Flag^=1

    if N!=1:
        R.append([N,1])

    return R

#根基
def Radical(N):
    """Nが素因数分解 N=p^a*q^b*r^c ...となるとき, pqr...を返す.

    N:非負整数
    """

    assert N>=0,"Nは非負整数ではない."
    a=1

    if N&1==0:
        a*=2
        while N&1==0:
            N>>=1

    if N%3==0:
        a*=3
        while N%3==0:
            N//=3

    k=5
    Flag=0
    while k*k<=N:
        if N%k==0:
            a*=k
            while N%k==0:
                N//=k
        k+=2+2*Flag
        Flag^=1

    if N>1:
        a*=N
    return a

def f(a,N):
    res=0
    while a:
        res+=a//N
        a//=N
    return res

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

Ans=float("inf")
for p,e in Prime_Factorization(M):
    Ans=min(Ans,(f(N,p)-f(N-K,p)-f(K,p))//e)

print(Ans)
0