結果

問題 No.816 Beautiful tuples
ユーザー simansiman
提出日時 2020-11-09 17:09:06
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 502 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 11,468 KB
実行使用メモリ 15,612 KB
最終ジャッジ日時 2023-09-29 22:12:42
合計ジャッジ時間 2,901 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 86 ms
15,424 KB
testcase_02 AC 87 ms
15,564 KB
testcase_03 WA -
testcase_04 AC 88 ms
15,608 KB
testcase_05 AC 91 ms
15,112 KB
testcase_06 AC 88 ms
15,548 KB
testcase_07 AC 88 ms
15,548 KB
testcase_08 AC 87 ms
15,612 KB
testcase_09 AC 87 ms
15,356 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 87 ms
15,340 KB
testcase_13 AC 86 ms
15,364 KB
testcase_14 AC 87 ms
15,312 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:27: warning: ambiguous first argument; put parentheses or a space even after `-' operator
Syntax OK

ソースコード

diff #

class Integer
  def divisor_list
    require 'prime'

    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..k).map { |n| base ** n }
    }.inject { |res, e| res + res.flat_map { |t| e.map { |v| t * v } } }.sort
  end
end

A, B = gets.split.map(&:to_i).sort

(A + B).divisor_list.each do |x|
  next if x > A + B
  next if x < B - A

  if (A + x) % B == 0 && (B + x) % A == 0
    puts x
    exit
  end
end

puts -1
0