結果

問題 No.816 Beautiful tuples
ユーザー simansiman
提出日時 2020-11-09 17:12:10
言語 Ruby
(3.3.0)
結果
AC  
実行時間 96 ms / 1,500 ms
コード長 536 bytes
コンパイル時間 59 ms
コンパイル使用メモリ 11,264 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2023-09-29 22:12:45
合計ジャッジ時間 2,355 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
15,284 KB
testcase_01 AC 91 ms
15,508 KB
testcase_02 AC 90 ms
15,380 KB
testcase_03 AC 91 ms
15,468 KB
testcase_04 AC 96 ms
15,336 KB
testcase_05 AC 90 ms
15,556 KB
testcase_06 AC 90 ms
15,312 KB
testcase_07 AC 90 ms
15,288 KB
testcase_08 AC 90 ms
15,384 KB
testcase_09 AC 90 ms
15,436 KB
testcase_10 AC 90 ms
15,572 KB
testcase_11 AC 91 ms
15,528 KB
testcase_12 AC 91 ms
15,616 KB
testcase_13 AC 92 ms
15,584 KB
testcase_14 AC 90 ms
15,236 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.rb:29: 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
  next if x == A
  next if x == B

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

puts -1
0