結果

問題 No.1243 約数加算
ユーザー 👑 obakyanobakyan
提出日時 2021-06-13 17:07:55
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 881 bytes
コンパイル時間 233 ms
コンパイル使用メモリ 5,300 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-24 20:05:16
合計ジャッジ時間 1,568 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 14 ms
4,376 KB
testcase_06 AC 30 ms
4,380 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 21 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local ffi = require("ffi")
local C = ffi.C
ffi.cdef[[
long long atoll(const char*);
]]

local function lltonumber(str)
  return C.atoll(str)
end

local function solve()
  local a, b = io.read():match("(%d+) (%d+)")
  a = lltonumber(a)
  b = lltonumber(b)
  local t = {}
  while a < b do
    local diff = b - a
    local mul = 1LL
    local tgt = 1LL
    while true do
      local v = mul + b % mul
      if diff < v then break end
      tgt = mul
      mul = mul + mul
    end
    mul = 1LL
    local v = tgt + b % tgt
    b = b - v
    while 0LL < v do
      if v % 2LL == 1LL then
        table.insert(t, mul)
      end
      v = v / 2LL
      mul = mul + mul
    end
  end
  print(#t)
  for i = #t, 1, -1 do
    local str = tostring(t[i]):gsub("LL", "")
    io.write(str)
    io.write(i == 1 and "\n" or " ")
  end
end
local q = io.read("*n", "*l")
for iq = 1, q do solve() end
0