結果

問題 No.1330 Multiply or Divide
ユーザー simansiman
提出日時 2022-02-28 06:49:44
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 387 bytes
コンパイル時間 488 ms
コンパイル使用メモリ 11,332 KB
実行使用メモリ 28,748 KB
最終ジャッジ日時 2023-09-20 14:26:36
合計ジャッジ時間 11,594 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 197 ms
27,964 KB
testcase_02 WA -
testcase_03 AC 86 ms
15,036 KB
testcase_04 AC 84 ms
15,156 KB
testcase_05 AC 81 ms
15,180 KB
testcase_06 AC 176 ms
26,868 KB
testcase_07 AC 453 ms
28,104 KB
testcase_08 AC 203 ms
28,536 KB
testcase_09 AC 212 ms
28,348 KB
testcase_10 AC 207 ms
28,448 KB
testcase_11 AC 200 ms
28,456 KB
testcase_12 AC 203 ms
28,528 KB
testcase_13 AC 82 ms
15,072 KB
testcase_14 AC 82 ms
15,308 KB
testcase_15 AC 82 ms
15,112 KB
testcase_16 AC 81 ms
15,144 KB
testcase_17 AC 81 ms
15,236 KB
testcase_18 AC 187 ms
28,488 KB
testcase_19 AC 196 ms
28,404 KB
testcase_20 AC 192 ms
28,384 KB
testcase_21 AC 196 ms
28,532 KB
testcase_22 AC 190 ms
28,580 KB
testcase_23 AC 197 ms
28,748 KB
testcase_24 AC 82 ms
15,112 KB
testcase_25 AC 81 ms
15,072 KB
testcase_26 AC 81 ms
15,332 KB
testcase_27 AC 83 ms
15,068 KB
testcase_28 AC 83 ms
15,016 KB
testcase_29 AC 84 ms
15,128 KB
testcase_30 AC 83 ms
15,244 KB
testcase_31 AC 82 ms
15,240 KB
testcase_32 AC 84 ms
15,160 KB
testcase_33 AC 83 ms
15,284 KB
testcase_34 AC 170 ms
25,224 KB
testcase_35 AC 107 ms
17,676 KB
testcase_36 AC 162 ms
24,052 KB
testcase_37 AC 156 ms
23,164 KB
testcase_38 AC 124 ms
20,072 KB
testcase_39 AC 112 ms
18,528 KB
testcase_40 AC 118 ms
19,216 KB
testcase_41 AC 105 ms
16,956 KB
testcase_42 AC 149 ms
22,472 KB
testcase_43 AC 159 ms
23,764 KB
testcase_44 AC 341 ms
26,956 KB
testcase_45 AC 426 ms
26,960 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:31: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:5: warning: assigned but unused variable - max_e
Syntax OK

ソースコード

diff #

N, M, P = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)

ans = Float::INFINITY
max_e = 1

A.each do |a|
  div_cnt = 0
  e = a

  while e % P == 0
    e /= P
    div_cnt += 1
  end

  next if e == 1

  cnt = 0
  x = 1
  while x * a <= M
    x *= e
    cnt += (1 + div_cnt)
  end

  if ans > cnt + 1
    ans = cnt + 1
  end
end

if ans == Float::INFINITY
  puts -1
else
  puts ans
end
0