結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 13:16:09 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 936 bytes |
| コンパイル時間 | 144 ms |
| コンパイル使用メモリ | 82,320 KB |
| 実行使用メモリ | 120,512 KB |
| 最終ジャッジ日時 | 2025-06-12 13:18:33 |
| 合計ジャッジ時間 | 4,895 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 45 WA * 1 |
ソースコード
import sys
def main():
input = sys.stdin.read().split()
N = int(input[0])
M = int(input[1])
P = int(input[2])
A = list(map(int, input[3:3+N]))
min_steps = float('inf')
for a in A:
ai = a
a_i = 0
while ai % P == 0:
a_i += 1
ai = ai // P
b_i = ai
product = (P ** a_i) * b_i
if product > M:
min_steps = min(min_steps, 1)
continue
if b_i == 1:
continue
required = M // product
k = 0
current = 1
while current <= required:
current *= b_i
k += 1
steps_i = k * (1 + a_i)
candidate = steps_i + 1
min_steps = min(min_steps, candidate)
if min_steps == float('inf'):
print(-1)
else:
print(min_steps)
if __name__ == "__main__":
main()
gew1fw