結果

問題 No.1383 Numbers of Product
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-02-07 22:17:23
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 753 ms / 2,000 ms
コード長 2,347 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 87,404 KB
実行使用メモリ 228,784 KB
最終ジャッジ日時 2023-08-14 22:16:17
合計ジャッジ時間 22,322 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
72,016 KB
testcase_01 AC 89 ms
71,616 KB
testcase_02 AC 90 ms
71,640 KB
testcase_03 AC 90 ms
72,076 KB
testcase_04 AC 91 ms
72,060 KB
testcase_05 AC 90 ms
71,948 KB
testcase_06 AC 90 ms
71,800 KB
testcase_07 AC 456 ms
163,004 KB
testcase_08 AC 443 ms
162,828 KB
testcase_09 AC 402 ms
196,372 KB
testcase_10 AC 753 ms
228,784 KB
testcase_11 AC 745 ms
228,480 KB
testcase_12 AC 737 ms
228,444 KB
testcase_13 AC 714 ms
228,540 KB
testcase_14 AC 577 ms
196,632 KB
testcase_15 AC 472 ms
162,920 KB
testcase_16 AC 728 ms
228,508 KB
testcase_17 AC 90 ms
71,396 KB
testcase_18 AC 91 ms
71,832 KB
testcase_19 AC 92 ms
71,828 KB
testcase_20 AC 91 ms
71,712 KB
testcase_21 AC 89 ms
71,844 KB
testcase_22 AC 89 ms
71,664 KB
testcase_23 AC 92 ms
71,424 KB
testcase_24 AC 90 ms
71,524 KB
testcase_25 AC 90 ms
71,840 KB
testcase_26 AC 89 ms
71,672 KB
testcase_27 AC 92 ms
72,076 KB
testcase_28 AC 104 ms
78,972 KB
testcase_29 AC 574 ms
196,468 KB
testcase_30 AC 742 ms
228,368 KB
testcase_31 AC 88 ms
71,560 KB
testcase_32 AC 176 ms
96,284 KB
testcase_33 AC 92 ms
72,148 KB
testcase_34 AC 96 ms
76,740 KB
testcase_35 AC 526 ms
211,192 KB
testcase_36 AC 651 ms
211,540 KB
testcase_37 AC 722 ms
228,452 KB
testcase_38 AC 747 ms
228,320 KB
testcase_39 AC 544 ms
228,172 KB
testcase_40 AC 526 ms
228,276 KB
testcase_41 AC 703 ms
228,676 KB
testcase_42 AC 713 ms
228,308 KB
testcase_43 AC 745 ms
228,660 KB
testcase_44 AC 524 ms
228,220 KB
testcase_45 AC 710 ms
228,596 KB
testcase_46 AC 89 ms
71,860 KB
testcase_47 AC 709 ms
228,476 KB
testcase_48 AC 706 ms
228,740 KB
testcase_49 AC 714 ms
228,408 KB
testcase_50 AC 722 ms
228,296 KB
testcase_51 AC 90 ms
71,612 KB
testcase_52 AC 91 ms
71,856 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 = int( (K**2+4*X)**0.5-K ) // 2
            
            for i in range(5):
                if l*(l+K) == X:
                    dic[X] += 1
                    break
                l += 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 = X+10

        l = int( (K**2+4*X)**0.5-K ) // 2

        for i in range(5):
            if l*(l+K) == X:
                dic[X] += 1
                bat += 1
                break
            l += 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