結果

問題 No.2125 Inverse Sum
ユーザー simansiman
提出日時 2022-11-19 19:32:14
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 629 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 11,912 KB
実行使用メモリ 16,436 KB
最終ジャッジ日時 2023-10-21 00:37:30
合計ジャッジ時間 4,854 ms
ジャッジサーバーID
(参考情報)
judge10 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
16,216 KB
testcase_01 AC 98 ms
16,216 KB
testcase_02 AC 98 ms
16,216 KB
testcase_03 AC 98 ms
16,216 KB
testcase_04 AC 100 ms
16,216 KB
testcase_05 WA -
testcase_06 AC 99 ms
16,216 KB
testcase_07 AC 100 ms
16,396 KB
testcase_08 AC 97 ms
16,216 KB
testcase_09 AC 97 ms
16,216 KB
testcase_10 AC 97 ms
16,216 KB
testcase_11 WA -
testcase_12 AC 96 ms
16,216 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 95 ms
16,216 KB
testcase_24 WA -
testcase_25 AC 99 ms
16,396 KB
testcase_26 AC 97 ms
16,216 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 96 ms
16,216 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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..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]
    if n != m
      ans << [m, n]
    end
  end
end

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