結果

問題 No.1330 Multiply or Divide
ユーザー gew1fw
提出日時 2025-06-12 20:47:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 889 bytes
コンパイル時間 229 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 138,764 KB
最終ジャッジ日時 2025-06-12 20:49:15
合計ジャッジ時間 5,774 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 38 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

import math

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    N = int(data[idx])
    idx += 1
    M = int(data[idx])
    idx += 1
    P = int(data[idx])
    idx += 1
    A = list(map(int, data[idx:idx+N]))
    
    a_list = []
    for ai in A:
        e = 0
        temp = ai
        while temp % P == 0 and temp != 0:
            e += 1
            temp = temp // P
        a = temp
        if a > 1:
            a_list.append((a, e))
    
    if not a_list:
        print(-1)
        return
    
    min_steps = float('inf')
    for a, e in a_list:
        steps = 0
        current = 1
        while current <= M:
            current *= a
            steps += 1
        total_cost = steps * (1 + e)
        if total_cost < min_steps:
            min_steps = total_cost
    
    print(min_steps)

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