結果

問題 No.1383 Numbers of Product
ユーザー 👑 KazunKazun
提出日時 2021-02-07 22:58:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 760 ms / 2,000 ms
コード長 4,681 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 87,196 KB
実行使用メモリ 186,392 KB
最終ジャッジ日時 2023-08-14 22:17:11
合計ジャッジ時間 22,930 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
72,216 KB
testcase_01 AC 89 ms
71,716 KB
testcase_02 AC 94 ms
71,668 KB
testcase_03 AC 90 ms
72,280 KB
testcase_04 AC 89 ms
72,264 KB
testcase_05 AC 87 ms
71,984 KB
testcase_06 AC 89 ms
72,040 KB
testcase_07 AC 457 ms
135,748 KB
testcase_08 AC 432 ms
136,136 KB
testcase_09 AC 555 ms
163,004 KB
testcase_10 AC 726 ms
185,376 KB
testcase_11 AC 736 ms
185,160 KB
testcase_12 AC 735 ms
185,324 KB
testcase_13 AC 673 ms
184,936 KB
testcase_14 AC 551 ms
162,624 KB
testcase_15 AC 471 ms
135,772 KB
testcase_16 AC 687 ms
185,348 KB
testcase_17 AC 91 ms
71,816 KB
testcase_18 AC 89 ms
71,716 KB
testcase_19 AC 90 ms
71,804 KB
testcase_20 AC 89 ms
71,864 KB
testcase_21 AC 91 ms
71,732 KB
testcase_22 AC 91 ms
71,804 KB
testcase_23 AC 90 ms
71,796 KB
testcase_24 AC 88 ms
71,960 KB
testcase_25 AC 91 ms
71,724 KB
testcase_26 AC 90 ms
71,788 KB
testcase_27 AC 89 ms
72,128 KB
testcase_28 AC 105 ms
79,212 KB
testcase_29 AC 588 ms
163,020 KB
testcase_30 AC 740 ms
185,332 KB
testcase_31 AC 92 ms
71,476 KB
testcase_32 AC 208 ms
104,244 KB
testcase_33 AC 92 ms
72,308 KB
testcase_34 AC 95 ms
72,792 KB
testcase_35 AC 673 ms
178,676 KB
testcase_36 AC 617 ms
178,712 KB
testcase_37 AC 722 ms
186,392 KB
testcase_38 AC 731 ms
186,200 KB
testcase_39 AC 744 ms
186,144 KB
testcase_40 AC 749 ms
186,168 KB
testcase_41 AC 720 ms
185,396 KB
testcase_42 AC 702 ms
185,600 KB
testcase_43 AC 760 ms
185,380 KB
testcase_44 AC 751 ms
185,260 KB
testcase_45 AC 721 ms
185,308 KB
testcase_46 AC 89 ms
71,524 KB
testcase_47 AC 695 ms
184,464 KB
testcase_48 AC 724 ms
185,260 KB
testcase_49 AC 712 ms
185,636 KB
testcase_50 AC 753 ms
184,476 KB
testcase_51 AC 89 ms
71,448 KB
testcase_52 AC 88 ms
71,692 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#Miller-Rabinの素数判定法
def Miller_Rabin_Primality_Test(N,Times=20):
    """Miller-Rabinによる整数Nの素数判定を行う.

    N:整数
    ※:Trueは正確にはProbably Trueである(Falseは確定False).
    """
    from random import randint as ri

    if N==2:
        return True

    if N==1 or N%2==0:
        return False

    q=N-1
    k=0
    while q&1==0:
        k+=1
        q>>=1

    for _ in range(Times):
        m=ri(2,N-1)
        y=pow(m,q,N)
        if y==1:
            continue

        flag=True
        for i in range(k):
            if (y+1)%N==0:
                flag=False
                break

            y*=y
            y%=N

        if flag:
            return False
    return True

#ポラード・ローアルゴリズムによって素因数を発見する
#参考元:https://judge.yosupo.jp/submission/6131
def Find_Factor_Rho(N):
    if N==1:
        return 1
    from math import gcd
    m=1<<(N.bit_length()//8+1)

    for c in range(1,99):
        f=lambda x:(x*x+c)%N
        y,r,q,g=2,1,1,1
        while g==1:
            x=y
            for i in range(r):
                y=f(y)
            k=0
            while k<r and g==1:
                for i in range(min(m, r - k)):
                    y=f(y)
                    q=q*abs(x - y)%N
                g=gcd(q,N)
                k+=m
            r <<=1

        if g<N:
            if Miller_Rabin_Primality_Test(g):
                return g
            elif Miller_Rabin_Primality_Test(N//g):
                return N//g
    return N

#ポラード・ローアルゴリズムによる素因数分解
#参考元:https://judge.yosupo.jp/submission/6131
def Pollard_Rho_Prime_Factorization(N):
    I=2
    res=[]
    while I*I<=N:
        if N%I==0:
            k=0
            while N%I==0:
                k+=1
                N//=I
            res.append([I,k])

        I+=1+(I%2)

        if I!=101 or N<2**20:
            continue

        while N>1:
            if Miller_Rabin_Primality_Test(N):
                res.append([N,1])
                N=1
            else:
                j=Find_Factor_Rho(N)
                k=0
                while N%j==0:
                    N//=j
                    k+=1
                res.append([j,k])
    if N>1:
        res.append([N,1])
    res.sort(key=lambda x:x[0])
    return res
#================================================
def General_Binary_Decrease_Search(L,R,cond,Integer=True,ep=1/(1<<20),Times=50):
    """条件式が単調減少であるとき,一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """

    if not(cond(L)):
        return None

    if cond(R):
        return R

    if Integer:
        L-=1
        while R-L>1:
            C=L+(R-L)//2
            if cond(C):
                L=C
            else:
                R=C
        return L
    else:
        while (R-L)>=ep and Times:
            Times-=1
            C=L+(R-L)/2
            if cond(C):
                L=C
            else:
                R=C
        return L

def Floor_Root(a,k):
    """floor(a^(1/k)) を求める.

    a:非負整数
    k:正の整数
    """
    assert 0<=a and 0<k
    if a==0:
        return 0
    if k==1:
        return a

    #大体の値を求める.
    x=int(pow(a,1/k))

    #増やす
    while pow(x+1,k)<=a:
        x+=1

    #減らす
    while pow(x,k)>a:
        x-=1
    return x
#================================================
def f(x):
    D=K*K+4*x
    R=Floor_Root(D,2)
    if R**2!=D:
        return None

    b=(-K+R)
    if b%2==1:
        return None
    else:
        return b//2

#================================================
from collections import defaultdict
N,K,M=map(int,input().split())


#B=1の解の範囲を求める.
alpha=General_Binary_Decrease_Search(0,N,lambda x:x*(x+K)<=N)

#B>=2の解を求める.
F=defaultdict(int)
a=1
while a*(a+K)*(a+2*K)<=N:
    p=a*(a+K)*(a+2*K)
    F[p]+=1

    q=a+3*K
    while p*q<=N:
        p*=q
        F[p]+=1
        q+=K
    a+=1

if M>=2:
    Ans=0
    for n in F:
        b=0
        t=f(n)
        if t!=None and 1<=t<=alpha:
            b=1

        if F[n]+b==M:
            Ans+=1
else:
    Ans=0
    beta=alpha
    for n in F:
        if F[n]==1:
            t=f(n)
            if t==None or not(1<=t<=alpha):
                Ans+=1
            else:
                beta-=1
        else:
            t=f(n)
            if t!=None and 1<=t<=alpha:
                beta-=1
    Ans+=beta
print(Ans)
0