結果

問題 No.2125 Inverse Sum
ユーザー simansiman
提出日時 2022-11-19 19:34:31
言語 Ruby
(3.3.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 591 bytes
コンパイル時間 353 ms
コンパイル使用メモリ 11,892 KB
実行使用メモリ 20,168 KB
最終ジャッジ日時 2023-10-21 00:38:59
合計ジャッジ時間 7,033 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
16,256 KB
testcase_01 AC 98 ms
16,256 KB
testcase_02 AC 98 ms
16,256 KB
testcase_03 AC 96 ms
16,256 KB
testcase_04 AC 97 ms
16,256 KB
testcase_05 AC 100 ms
16,256 KB
testcase_06 AC 100 ms
16,260 KB
testcase_07 AC 104 ms
16,436 KB
testcase_08 AC 98 ms
16,256 KB
testcase_09 AC 97 ms
16,256 KB
testcase_10 AC 97 ms
16,256 KB
testcase_11 AC 96 ms
16,256 KB
testcase_12 AC 96 ms
16,256 KB
testcase_13 AC 97 ms
16,256 KB
testcase_14 AC 97 ms
16,256 KB
testcase_15 AC 98 ms
16,256 KB
testcase_16 AC 99 ms
16,256 KB
testcase_17 AC 103 ms
16,256 KB
testcase_18 AC 102 ms
16,256 KB
testcase_19 AC 99 ms
16,256 KB
testcase_20 AC 104 ms
16,256 KB
testcase_21 AC 102 ms
16,256 KB
testcase_22 AC 101 ms
16,256 KB
testcase_23 AC 103 ms
16,256 KB
testcase_24 AC 104 ms
16,436 KB
testcase_25 AC 102 ms
16,436 KB
testcase_26 AC 97 ms
16,256 KB
testcase_27 AC 189 ms
20,168 KB
testcase_28 AC 168 ms
19,816 KB
testcase_29 AC 136 ms
18,576 KB
testcase_30 AC 100 ms
16,256 KB
testcase_31 AC 178 ms
19,816 KB
testcase_32 AC 120 ms
17,748 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

require 'prime'

class Integer
  def divisor_list
    return [] if self <= 0
    return [1] if self == 1

    prime_division.map.with_index { |(base, k), i|
      s = i.zero? ? 0 : 1
      (s..2 * 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)
gcd = A.gcd(B)

P = A / gcd
Q = B / gcd
ans = []

L = Q ** 2
Q.divisor_list.each do |a|
  if (a + Q) % P == 0
    n = (a + Q) / P
    b = L / a
    m = (b + Q) / P

    ans << [n, m]
  end
end

puts ans.size
ans.each do |n, m|
  puts "#{n} #{m}"
end
0