結果

問題 No.1383 Numbers of Product
ユーザー 👑 KazunKazun
提出日時 2021-02-07 23:06:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 734 ms / 2,000 ms
コード長 2,331 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 168,420 KB
最終ジャッジ日時 2024-05-02 10:22:57
合計ジャッジ時間 18,269 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,144 KB
testcase_01 AC 41 ms
53,888 KB
testcase_02 AC 43 ms
53,760 KB
testcase_03 AC 41 ms
54,144 KB
testcase_04 AC 41 ms
54,144 KB
testcase_05 AC 42 ms
53,760 KB
testcase_06 AC 42 ms
54,272 KB
testcase_07 AC 351 ms
127,780 KB
testcase_08 AC 343 ms
128,032 KB
testcase_09 AC 430 ms
150,692 KB
testcase_10 AC 595 ms
165,972 KB
testcase_11 AC 571 ms
166,104 KB
testcase_12 AC 602 ms
166,232 KB
testcase_13 AC 525 ms
166,364 KB
testcase_14 AC 455 ms
150,568 KB
testcase_15 AC 352 ms
127,644 KB
testcase_16 AC 615 ms
166,468 KB
testcase_17 AC 44 ms
54,016 KB
testcase_18 AC 46 ms
53,888 KB
testcase_19 AC 45 ms
53,888 KB
testcase_20 AC 43 ms
53,632 KB
testcase_21 AC 46 ms
54,016 KB
testcase_22 AC 45 ms
53,760 KB
testcase_23 AC 42 ms
53,760 KB
testcase_24 AC 45 ms
53,760 KB
testcase_25 AC 45 ms
53,888 KB
testcase_26 AC 45 ms
54,016 KB
testcase_27 AC 45 ms
54,016 KB
testcase_28 AC 69 ms
68,736 KB
testcase_29 AC 461 ms
150,560 KB
testcase_30 AC 662 ms
166,100 KB
testcase_31 AC 46 ms
53,760 KB
testcase_32 AC 160 ms
101,408 KB
testcase_33 AC 46 ms
54,144 KB
testcase_34 AC 49 ms
55,424 KB
testcase_35 AC 558 ms
161,868 KB
testcase_36 AC 545 ms
162,248 KB
testcase_37 AC 636 ms
168,420 KB
testcase_38 AC 631 ms
168,412 KB
testcase_39 AC 602 ms
168,032 KB
testcase_40 AC 592 ms
168,408 KB
testcase_41 AC 710 ms
168,284 KB
testcase_42 AC 734 ms
168,028 KB
testcase_43 AC 661 ms
166,236 KB
testcase_44 AC 621 ms
166,484 KB
testcase_45 AC 644 ms
166,236 KB
testcase_46 AC 47 ms
53,760 KB
testcase_47 AC 593 ms
165,936 KB
testcase_48 AC 542 ms
165,888 KB
testcase_49 AC 567 ms
166,320 KB
testcase_50 AC 585 ms
165,808 KB
testcase_51 AC 45 ms
53,632 KB
testcase_52 AC 46 ms
53,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#================================================
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