結果

問題 No.1330 Multiply or Divide
ユーザー tktk_snsn
提出日時 2021-01-08 23:09:25
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 704 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 118,272 KB
最終ジャッジ日時 2024-11-16 15:42:08
合計ジャッジ時間 5,416 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M, P = map(int, input().split())
A = list(map(int, input().split()))

if M == 1:
    print(0)
    exit()

ok = []
ng = []
for a in A:
    if a == 1:
        continue
    if a % P == 0:
        ng.append(a)
    else:
        ok.append(a)

if ok:
    v = max(ok)
    ans = 0
    x = 1
    while x < M:
        x *= v
        ans += 1
    print(ans)
    exit()

if ng:
    v = max(ng)
    if v >= M:
        print(1)
        exit()
    tmp = v
    while tmp % P == 0:
        tmp //= P
    if tmp == 1:
        print(-1)
        exit()
    ans = 0
    x = 1
    while x < M:
        if x % P == 0:
            x //= P
        else:
            x *= v
        ans += 1
    print(ans)
    exit()

print(-1)
0