結果

問題 No.1383 Numbers of Product
ユーザー 👑 SPD_9X2SPD_9X2
提出日時 2021-02-07 22:17:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 705 ms / 2,000 ms
コード長 2,347 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 226,840 KB
最終ジャッジ日時 2024-05-02 10:21:26
合計ジャッジ時間 19,040 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
54,656 KB
testcase_01 AC 42 ms
54,144 KB
testcase_02 AC 42 ms
54,016 KB
testcase_03 AC 44 ms
54,656 KB
testcase_04 AC 45 ms
54,272 KB
testcase_05 AC 45 ms
54,528 KB
testcase_06 AC 45 ms
54,016 KB
testcase_07 AC 422 ms
160,924 KB
testcase_08 AC 399 ms
161,044 KB
testcase_09 AC 421 ms
194,460 KB
testcase_10 AC 705 ms
226,464 KB
testcase_11 AC 677 ms
226,340 KB
testcase_12 AC 686 ms
226,588 KB
testcase_13 AC 641 ms
226,468 KB
testcase_14 AC 544 ms
194,492 KB
testcase_15 AC 423 ms
160,924 KB
testcase_16 AC 645 ms
226,460 KB
testcase_17 AC 43 ms
54,400 KB
testcase_18 AC 41 ms
54,400 KB
testcase_19 AC 42 ms
54,272 KB
testcase_20 AC 40 ms
54,400 KB
testcase_21 AC 39 ms
54,784 KB
testcase_22 AC 40 ms
54,912 KB
testcase_23 AC 41 ms
54,016 KB
testcase_24 AC 42 ms
54,272 KB
testcase_25 AC 41 ms
54,400 KB
testcase_26 AC 44 ms
54,400 KB
testcase_27 AC 42 ms
54,912 KB
testcase_28 AC 60 ms
75,608 KB
testcase_29 AC 536 ms
194,848 KB
testcase_30 AC 698 ms
226,456 KB
testcase_31 AC 45 ms
54,144 KB
testcase_32 AC 146 ms
97,784 KB
testcase_33 AC 45 ms
54,528 KB
testcase_34 AC 48 ms
61,056 KB
testcase_35 AC 498 ms
209,708 KB
testcase_36 AC 579 ms
209,828 KB
testcase_37 AC 666 ms
226,460 KB
testcase_38 AC 700 ms
226,840 KB
testcase_39 AC 543 ms
226,464 KB
testcase_40 AC 539 ms
226,460 KB
testcase_41 AC 642 ms
226,460 KB
testcase_42 AC 678 ms
226,464 KB
testcase_43 AC 696 ms
226,460 KB
testcase_44 AC 544 ms
226,636 KB
testcase_45 AC 696 ms
226,328 KB
testcase_46 AC 44 ms
54,784 KB
testcase_47 AC 690 ms
226,584 KB
testcase_48 AC 686 ms
226,720 KB
testcase_49 AC 664 ms
226,464 KB
testcase_50 AC 674 ms
226,592 KB
testcase_51 AC 42 ms
54,272 KB
testcase_52 AC 43 ms
54,528 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