結果

問題 No.1595 The Final Digit
ユーザー 👑 obakyanobakyan
提出日時 2021-07-22 16:46:12
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 49 ms
コンパイル使用メモリ 5,332 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-24 14:13:53
合計ジャッジ時間 1,218 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
4,380 KB
testcase_01 AC 3 ms
4,376 KB
testcase_02 AC 3 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 4 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 4 ms
4,380 KB
testcase_07 AC 3 ms
4,376 KB
testcase_08 AC 3 ms
4,376 KB
testcase_09 AC 3 ms
4,380 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 3 ms
4,376 KB
testcase_12 AC 3 ms
4,376 KB
testcase_13 AC 3 ms
4,384 KB
testcase_14 AC 4 ms
4,376 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 3 ms
4,376 KB
testcase_17 AC 3 ms
4,376 KB
testcase_18 AC 3 ms
4,376 KB
testcase_19 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil

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 p, q, r, k = io.read():match("(%d+) (%d+) (%d+) (%d+)")
p, q, r = tonumber(p), tonumber(q), tonumber(r)
k = lltonumber(k)

local t = {{}}
for i = 1, 1000 do
  local v = i - 1
  local p1 = v % 10
  v = mfl(v / 10)
  local p2 = v % 10
  local p3 = mfl(v / 10)
  local d = (p1 + p2 + p3) % 10
  local dst = d * 100 + p3 * 10 + p2 + 1
  t[1][i] = dst
end
for i = 2, 100 do
  t[i] = {}
  for j = 1, 1000 do
    t[i][j] = t[i - 1][ t[i - 1][j] ]
  end
end
p = p % 10
q = q % 10
r = r % 10
if k == 1LL then
  print(p)
elseif k == 2LL then
  print(q)
elseif k == 3LL then
  print(r)
else
  k = k - 1LL
  local cur = p + q * 10 + r * 100 + 1
  for i = 1, 100 do
    if k % 2LL == 1LL then
      cur = t[i][cur]
    end
    k = k / 2LL
  end
  print((cur + 9) % 10)
end
0