結果

問題 No.1383 Numbers of Product
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-02-07 22:00:22
言語 PyPy3
(7.3.13)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,449 bytes
コンパイル時間 557 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 228,500 KB
最終ジャッジ日時 2023-09-17 21:37:03
合計ジャッジ時間 50,822 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,648 KB
testcase_01 AC 90 ms
71,888 KB
testcase_02 AC 96 ms
71,856 KB
testcase_03 AC 90 ms
71,956 KB
testcase_04 AC 90 ms
71,576 KB
testcase_05 AC 91 ms
71,424 KB
testcase_06 AC 92 ms
71,876 KB
testcase_07 AC 1,339 ms
162,460 KB
testcase_08 AC 1,302 ms
162,540 KB
testcase_09 AC 494 ms
195,812 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 AC 1,978 ms
228,376 KB
testcase_14 AC 1,663 ms
195,864 KB
testcase_15 AC 1,397 ms
162,388 KB
testcase_16 TLE -
testcase_17 AC 89 ms
71,956 KB
testcase_18 AC 90 ms
71,728 KB
testcase_19 AC 89 ms
71,420 KB
testcase_20 AC 90 ms
71,608 KB
testcase_21 AC 90 ms
71,676 KB
testcase_22 AC 91 ms
71,788 KB
testcase_23 AC 91 ms
71,924 KB
testcase_24 AC 94 ms
71,696 KB
testcase_25 AC 90 ms
71,724 KB
testcase_26 AC 90 ms
71,568 KB
testcase_27 AC 100 ms
76,840 KB
testcase_28 AC 106 ms
78,912 KB
testcase_29 AC 1,622 ms
195,912 KB
testcase_30 TLE -
testcase_31 AC 90 ms
71,728 KB
testcase_32 AC 183 ms
95,848 KB
testcase_33 AC 96 ms
76,916 KB
testcase_34 AC 97 ms
76,824 KB
testcase_35 AC 585 ms
211,092 KB
testcase_36 AC 1,801 ms
211,152 KB
testcase_37 TLE -
testcase_38 TLE -
testcase_39 AC 662 ms
228,024 KB
testcase_40 AC 666 ms
228,028 KB
testcase_41 TLE -
testcase_42 TLE -
testcase_43 TLE -
testcase_44 AC 670 ms
228,036 KB
testcase_45 TLE -
testcase_46 AC 90 ms
71,648 KB
testcase_47 TLE -
testcase_48 TLE -
testcase_49 TLE -
testcase_50 TLE -
testcase_51 AC 92 ms
71,744 KB
testcase_52 AC 91 ms
71,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

"""

Aで場合分けしたい!!
AはX以下

Bはあまり大きくならない
Bに関してAを二分探索


B = 1の時
A * (A+K) がすでに多いのが嫌だ

B = 2以上の場合は
列挙可能

列挙した後、M個の奴 or M-1個のやつに関して
B=1があるかを判定すればよい
Aを二分探索すれば見つかる
M = 1の場合だけ嫌だな

別で処理する

A*(A+K)の中で、バッティングした数を覚えておく
それ以外の A*(A+K)

"""

import sys
import heapq
from collections import deque
from sys import stdin

def want(A,B):
    ret = A
    for i in range(B):
        ret *= A + (i+1)*K
    return ret

dic = {}
N,K,M = map(int,stdin.readline().split())

if M != 1:

    # B >= 2 の全列挙
    for B in range(2,22):
        for A in range(1,10**9):
            X = want(A,B)
            if X <= N:
                if X not in dic:
                    dic[X] = 1
                else:
                    dic[X] += 1
            else:
                break

    ans = 0
    #B = 1があるかを検索

    for X in dic:
        
        if M-1 <= dic[X] <= M:
            l = 0
            r = 10**18

            while r-l != 1:
                m = (l+r)//2
                if m*(m+K) <= X:
                    l = m
                else:
                    r = m

            if l*(l+K) == X:
                dic[X] += 1

            if dic[X] == M:
                ans += 1

    print (ans)

else: #M==1の場合

    # B >= 2 の全列挙
    for B in range(2,22):
        for A in range(1,10**9):
            X = want(A,B)
            if X <= N:
                if X not in dic:
                    dic[X] = 1
                else:
                    dic[X] += 1
            else:
                break

    ans = 0
    bat = 0
    
    #B = 1があるかを検索
    #print (dic)

    for X in dic:
        
        l = 0
        r = 10**18

        while r-l != 1:
            m = (l+r)//2
            if m*(m+K) <= X:
                l = m
            else:
                r = m

        #print (X,l,K)
        if l*(l+K) == X:
            bat += 1
            dic[X] += 1

        if dic[X] == M:
            ans += 1

    #print (ans,bat,file=sys.stderr)
    
    #有効な最大のAを求める
    l = 0
    r = 10**18
    while r-l != 1:
        m = (l+r)//2
        if m * (m+K) <= N:
            l = m
        else:
            r = m

    ans += l - bat
    print (ans)
0