結果
| 問題 |
No.1383 Numbers of Product
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-20 20:45:03 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 2,249 bytes |
| コンパイル時間 | 154 ms |
| コンパイル使用メモリ | 82,904 KB |
| 実行使用メモリ | 638,720 KB |
| 最終ジャッジ日時 | 2025-03-20 20:45:16 |
| 合計ジャッジ時間 | 4,218 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 MLE * 1 |
| other | AC * 5 TLE * 1 -- * 45 |
ソースコード
import sys
from collections import defaultdict
def solve():
N, K, M = map(int, sys.stdin.readline().split())
count = defaultdict(int)
L = 2
while True:
# Check if the minimal product (A=1) is possible
product = 1
overflow = False
for i in range(L):
term = 1 + i * K
if product > N // term:
overflow = True
break
product *= term
if product > N:
overflow = True
break
if overflow:
break # No more L to consider
# Binary search to find the maximum A for current L
low = 1
high = N # Upper bound for A
best_A = 0
while low <= high:
mid = (low + high) // 2
current_product = 1
valid = True
for i in range(L):
term = mid + i * K
if term < 1: # A must be >=1, so terms cannot be <=0
valid = False
break
if current_product > N // term:
valid = False
break
current_product *= term
if current_product > N:
valid = False
break
if valid:
best_A = mid
low = mid + 1
else:
high = mid - 1
if best_A == 0:
L += 1
continue
# Now compute the product for each A from 1 to best_A
for A in range(1, best_A + 1):
current_product = 1
for i in range(L):
term = A + i * K
if term < 1:
current_product = N + 1
break
if current_product > N // term:
current_product = N + 1
break
current_product *= term
if current_product > N:
break
if current_product <= N:
count[current_product] += 1
L += 1
# Calculate the answer
ans = 0
for x in count:
if 1 <= x <= N and count[x] == M:
ans += 1
print(ans)
solve()
lam6er