結果

問題 No.1809 Divide NCK
ユーザー ShirotsumeShirotsume
提出日時 2022-01-14 22:33:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 1,553 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 82,548 KB
実行使用メモリ 66,008 KB
最終ジャッジ日時 2024-04-30 16:01:58
合計ジャッジ時間 3,368 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 46 ms
57,644 KB
testcase_01 AC 48 ms
56,952 KB
testcase_02 AC 48 ms
57,428 KB
testcase_03 AC 44 ms
56,444 KB
testcase_04 AC 45 ms
57,832 KB
testcase_05 AC 45 ms
58,224 KB
testcase_06 AC 45 ms
57,208 KB
testcase_07 AC 45 ms
57,476 KB
testcase_08 AC 45 ms
57,044 KB
testcase_09 AC 45 ms
57,440 KB
testcase_10 AC 44 ms
56,276 KB
testcase_11 AC 50 ms
64,772 KB
testcase_12 AC 45 ms
57,180 KB
testcase_13 AC 49 ms
64,072 KB
testcase_14 AC 47 ms
58,500 KB
testcase_15 AC 50 ms
63,240 KB
testcase_16 AC 49 ms
62,456 KB
testcase_17 AC 49 ms
62,148 KB
testcase_18 AC 52 ms
64,636 KB
testcase_19 AC 51 ms
62,648 KB
testcase_20 AC 50 ms
62,992 KB
testcase_21 AC 50 ms
66,008 KB
testcase_22 AC 44 ms
56,952 KB
testcase_23 AC 45 ms
58,232 KB
testcase_24 AC 45 ms
58,160 KB
testcase_25 AC 46 ms
56,728 KB
testcase_26 AC 45 ms
58,652 KB
testcase_27 AC 44 ms
56,152 KB
testcase_28 AC 45 ms
57,276 KB
testcase_29 AC 48 ms
63,356 KB
testcase_30 AC 48 ms
63,692 KB
testcase_31 AC 48 ms
63,868 KB
testcase_32 AC 49 ms
65,896 KB
testcase_33 AC 48 ms
63,304 KB
testcase_34 AC 48 ms
63,740 KB
testcase_35 AC 49 ms
63,360 KB
testcase_36 AC 48 ms
63,860 KB
testcase_37 AC 49 ms
64,756 KB
testcase_38 AC 56 ms
65,588 KB
testcase_39 AC 53 ms
65,348 KB
testcase_40 AC 50 ms
65,504 KB
testcase_41 AC 50 ms
65,872 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