結果
| 問題 |
No.1448 和差算
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-26 21:51:55 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,131 bytes |
| コンパイル時間 | 276 ms |
| コンパイル使用メモリ | 5,632 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-22 12:53:57 |
| 合計ジャッジ時間 | 1,472 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 36 |
ソースコード
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 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 modpow(src, pow)
local res = 1
while 0LL < pow do
if pow % 2LL == 1LL then
res = bmul(res, src)
end
src = bmul(src, src)
pow = pow / 2LL
end
return res
end
local a, b, c, d = io.read("*n", "*n", "*n", "*n", "*l")
local n = lltonumber(io.read())
local n2 = n % 8LL
local retmax = false
local as = {a, a, b, b}
local bs = {c, d, c, d}
for i = 1, 4 do
local az = as[i]
local bz = bs[i]
local j = 0LL
while j < n2 do
az, bz = az - bz, az + bz
j = j + 1LL
end
local v = az + bz
if i == 1 or retmax < v then
retmax = v
end
end
while retmax < 0 do
retmax = retmax + mod
end
retmax = retmax % mod
local rep = n / 8LL
local mul = modpow(16, rep)
print(bmul(retmax, mul))