結果

問題 No.1136 Four Points Tour
ユーザー 👑 obakyan
提出日時 2020-11-17 23:34:00
言語 Lua
(LuaJit 2.1.1734355927)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,216 bytes
コンパイル時間 370 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 08:33:31
合計ジャッジ時間 1,455 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 41
権限があれば一括ダウンロードができます

ソースコード

diff #

local mod = 1000000007
local mfl = math.floor

local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end

local function badd(x, y)
  return (x + y) % mod
end

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 n = io.read()
n = lltonumber(n)

mat = {0, 1, 3, 2}
ret = {1, 0, 1, 0}

while 0LL < n do
  if n % 2LL == 1LL then
    local a = badd(bmul(ret[1], mat[1]), bmul(ret[2], mat[3]))
    local b = badd(bmul(ret[1], mat[2]), bmul(ret[2], mat[4]))
    local c = badd(bmul(ret[3], mat[1]), bmul(ret[4], mat[3]))
    local d = badd(bmul(ret[3], mat[2]), bmul(ret[4], mat[4]))
    ret[1], ret[2], ret[3], ret[4] = a, b, c, d
  end
  do
    local a = badd(bmul(mat[1], mat[1]), bmul(mat[2], mat[3]))
    local b = badd(bmul(mat[1], mat[2]), bmul(mat[2], mat[4]))
    local c = badd(bmul(mat[3], mat[1]), bmul(mat[4], mat[3]))
    local d = badd(bmul(mat[3], mat[2]), bmul(mat[4], mat[4]))
    mat[1], mat[2], mat[3], mat[4] = a, b, c, d
  end
  n = n / 2LL
end
print(ret[1])
0