結果

問題 No.2125 Inverse Sum
ユーザー simansiman
提出日時 2022-11-19 19:29:12
言語 Ruby
(3.3.0)
結果
TLE  
実行時間 -
コード長 590 bytes
コンパイル時間 726 ms
コンパイル使用メモリ 11,908 KB
実行使用メモリ 20,876 KB
最終ジャッジ日時 2023-10-21 00:35:40
合計ジャッジ時間 6,747 ms
ジャッジサーバーID
(参考情報)
judge10 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
16,288 KB
testcase_01 AC 94 ms
16,288 KB
testcase_02 AC 95 ms
16,288 KB
testcase_03 AC 95 ms
16,288 KB
testcase_04 AC 92 ms
16,288 KB
testcase_05 AC 93 ms
16,288 KB
testcase_06 AC 94 ms
16,288 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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)
gcd = A.gcd(B)

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

L = Q ** 2
L.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