結果

問題 No.1383 Numbers of Product
ユーザー 👑 KazunKazun
提出日時 2021-02-07 22:56:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 4,681 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 87,312 KB
実行使用メモリ 185,432 KB
最終ジャッジ日時 2023-09-18 00:13:26
合計ジャッジ時間 24,866 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
72,324 KB
testcase_01 AC 91 ms
71,484 KB
testcase_02 AC 93 ms
71,832 KB
testcase_03 WA -
testcase_04 AC 93 ms
72,064 KB
testcase_05 WA -
testcase_06 AC 92 ms
71,808 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 568 ms
162,656 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 91 ms
71,628 KB
testcase_18 AC 94 ms
71,728 KB
testcase_19 AC 94 ms
71,624 KB
testcase_20 AC 92 ms
71,884 KB
testcase_21 AC 93 ms
71,740 KB
testcase_22 AC 92 ms
71,704 KB
testcase_23 AC 92 ms
71,620 KB
testcase_24 AC 93 ms
71,888 KB
testcase_25 AC 94 ms
71,896 KB
testcase_26 AC 94 ms
71,732 KB
testcase_27 WA -
testcase_28 AC 114 ms
79,068 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 94 ms
71,792 KB
testcase_32 AC 218 ms
104,140 KB
testcase_33 WA -
testcase_34 AC 98 ms
72,856 KB
testcase_35 AC 736 ms
178,480 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 785 ms
185,216 KB
testcase_40 AC 796 ms
185,196 KB
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 825 ms
185,192 KB
testcase_45 WA -
testcase_46 AC 92 ms
71,488 KB
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 AC 89 ms
71,868 KB
testcase_52 AC 92 ms
71,572 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*N
    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