結果

問題 No.1809 Divide NCK
ユーザー ShirotsumeShirotsume
提出日時 2022-01-14 22:33:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,553 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 79,152 KB
最終ジャッジ日時 2023-08-12 20:55:27
合計ジャッジ時間 7,227 ms
ジャッジサーバーID
(参考情報)
judge9 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
74,384 KB
testcase_01 AC 116 ms
74,692 KB
testcase_02 AC 117 ms
74,344 KB
testcase_03 AC 115 ms
74,792 KB
testcase_04 AC 117 ms
74,732 KB
testcase_05 AC 115 ms
74,828 KB
testcase_06 AC 116 ms
74,680 KB
testcase_07 AC 114 ms
74,544 KB
testcase_08 AC 118 ms
74,728 KB
testcase_09 AC 114 ms
74,612 KB
testcase_10 AC 117 ms
74,860 KB
testcase_11 AC 124 ms
79,100 KB
testcase_12 AC 117 ms
74,564 KB
testcase_13 AC 121 ms
78,516 KB
testcase_14 AC 118 ms
74,384 KB
testcase_15 AC 122 ms
78,528 KB
testcase_16 AC 121 ms
78,548 KB
testcase_17 AC 120 ms
78,824 KB
testcase_18 AC 126 ms
79,120 KB
testcase_19 AC 127 ms
79,012 KB
testcase_20 AC 122 ms
78,708 KB
testcase_21 AC 124 ms
79,152 KB
testcase_22 AC 119 ms
74,836 KB
testcase_23 AC 116 ms
74,384 KB
testcase_24 AC 116 ms
74,320 KB
testcase_25 AC 120 ms
74,532 KB
testcase_26 AC 122 ms
74,900 KB
testcase_27 AC 120 ms
74,780 KB
testcase_28 AC 118 ms
74,696 KB
testcase_29 AC 123 ms
78,424 KB
testcase_30 AC 121 ms
78,572 KB
testcase_31 AC 119 ms
78,636 KB
testcase_32 AC 122 ms
78,868 KB
testcase_33 AC 119 ms
78,564 KB
testcase_34 AC 120 ms
78,648 KB
testcase_35 AC 119 ms
78,632 KB
testcase_36 AC 119 ms
78,668 KB
testcase_37 AC 119 ms
78,824 KB
testcase_38 AC 122 ms
78,928 KB
testcase_39 AC 120 ms
78,752 KB
testcase_40 AC 119 ms
78,712 KB
testcase_41 AC 119 ms
78,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
import random
from collections import defaultdict
def is_prime(n):
    if n==2:
        return True
    if n==1 or n&1==0:
        return False
    d=(n-1)>>1
    while d&1==0:
        d>>=1

    for k in range(100):
        a=random.randint(1,n-1)
        t=d
        y=pow(a, t, n)
        while t!=n-1 and y!=1 and y!=n-1:
            y=(y*y)%n
            t<<=1
        if y!=n-1 and t&1==0:
            return False
    return True

def prime_fact(N):
    res=defaultdict(int)
    if N==1:
        return res
    p=2
    while(p<=10**4 and N>1):
        if N%p==0:
            while(N%p==0):
                res[p]+=1
                N//=p
        p+=1
    while(N>1):
        if is_prime(N):
            res[N]+=1
            break
        x=random.randrange(N)
        y=(x*x+1)%N
        i=1
        while(True):
            d=gcd(abs(x-y),N)
            if d==1:
                i+=1
            elif d==N:
                res[N]+=1
                return res
            else:
                res[d]+=1
                N//=d
                break
            x=(x*x+1)%N
            y=(y*y+1)%N
            y=(y*y+1)%N
    return res
n, k, m = map(int,input().split())

def count(x, y):
    #1*2*...*xをyで割り切る回数
    ret = 0
    rui = 0
    for i in range(65, -1, -1):
        now = x // (y ** i)
        ret += now
        rui += now
    return ret

p = prime_fact(m)
ans = 10 ** 18
for num, v in p.items():
    now = count(n, num) - count(k, num) - count(n - k, num)
    ans = min(ans, now // v)
print(ans)
0