結果

問題 No.1383 Numbers of Product
ユーザー gew1fw
提出日時 2025-06-12 15:42:55
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 2,047 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 82,668 KB
実行使用メモリ 618,008 KB
最終ジャッジ日時 2025-06-12 15:43:00
合計ジャッジ時間 4,289 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 MLE * 1 -- * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
from collections import defaultdict

def main():
    N, K, M = map(int, input().split())
    count = defaultdict(int)
    
    L = 2
    while True:
        min_product = 1
        for i in range(L):
            term = 1 + i * K
            if term > N:
                min_product = N + 1
                break
            min_product *= term
            if min_product > N:
                break
        if min_product > N:
            break
        
        low = 1
        high = N
        A_max = 0
        
        while low <= high:
            mid = (low + high) // 2
            product = 1
            valid = True
            for i in range(L):
                term = mid + i * K
                if term > N:
                    valid = False
                    break
                if product > N // term:
                    valid = False
                    break
                product *= term
                if product > N:
                    valid = False
                    break
            if valid:
                A_max = mid
                low = mid + 1
            else:
                high = mid - 1
        
        if A_max == 0:
            L += 1
            continue
        
        current_A = 1
        while current_A <= A_max:
            product = 1
            overflow = False
            for i in range(L):
                term = current_A + i * K
                if term > N:
                    overflow = True
                    break
                if product > N // term:
                    overflow = True
                    break
                product *= term
                if product > N:
                    overflow = True
                    break
            if overflow:
                current_A += 1
                continue
            count[product] += 1
            current_A += 1
        
        L += 1
    
    result = 0
    for x in count:
        if x <= N and count[x] == M:
            result += 1
    print(result)

if __name__ == "__main__":
    main()
0