結果

問題 No.1243 約数加算
ユーザー maimai
提出日時 2020-10-02 21:45:35
言語 Ruby
(3.3.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 668 bytes
コンパイル時間 40 ms
コンパイル使用メモリ 11,244 KB
実行使用メモリ 15,412 KB
最終ジャッジ日時 2023-09-23 04:32:38
合計ジャッジ時間 1,761 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 84 ms
14,980 KB
testcase_01 AC 81 ms
15,192 KB
testcase_02 AC 81 ms
15,056 KB
testcase_03 AC 83 ms
15,188 KB
testcase_04 AC 86 ms
15,220 KB
testcase_05 AC 88 ms
15,344 KB
testcase_06 AC 87 ms
15,048 KB
testcase_07 AC 84 ms
15,412 KB
testcase_08 AC 85 ms
15,236 KB
testcase_09 AC 79 ms
15,072 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

def lscan; gets.split.map(&:to_i); end

def solve(a, b)
  answer = []
  step = 1
  while a < b
    if b - a == step
      answer << step
      a += step
    elsif b - a < step
      step /= 2
    elsif b - a > step*2
      if a%(step*2) == 0
        step *= 2
      else
        answer << step
        a += step
      end
    else
      answer << step
      a += step
    end
  end
  answer
end

# def check(a, b, ans)
#   p a
#   ans.each do |x|
#     abort "#{x}" unless a%x == 0
#     p a += x
#   end
#   abort `#{a} != #{b}` unless a == b
#   true
# end

gets.to_i.times do 
  a,b = lscan
  ans = solve(a, b)
  p ans.size
  puts ans*' '
  # p check(a, b, ans)
end
0