結果

問題 No.1330 Multiply or Divide
ユーザー tamura2004
提出日時 2021-01-21 13:12:42
言語 Ruby
(3.4.1)
結果
WA  
実行時間 -
コード長 330 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 7,424 KB
実行使用メモリ 27,520 KB
最終ジャッジ日時 2024-12-24 12:48:11
合計ジャッジ時間 10,576 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 39 WA * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:15: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Main.rb:1: warning: assigned but unused variable - n
Syntax OK

ソースコード

diff #

n,m,p = gets.to_s.split.map{ |v| v.to_i }
a = gets.to_s.split.map{ |v| v.to_i }
b = a.map do |v|
  x = v
  while x >= p && x % p == 0
    x /= p
  end
  x
end

am = a.max
bm = b.max

if am < m && bm == 1
  puts -1
  exit
end

ans = 0
x = 1
while x <= m
  ans += 1
  if x * am <= m
    x *= bm
  else
    x *= am
  end
end
puts ans
0