結果

問題 No.251 大きな桁の復習問題(1)
ユーザー 👑 obakyan
提出日時 2020-05-04 21:59:51
言語 Lua
(LuaJit 2.1.1734355927)
結果
TLE  
実行時間 -
コード長 919 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 6,684 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-06-25 00:43:42
合計ジャッジ時間 7,035 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 3
other AC * 9 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

local mod = 129402307
local mfl = math.floor

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

local ns = io.read()
local ms = io.read()

local mul = 1
local n = 0
for i = #ns, 1, -1 do
  local v = ns:sub(i, i):byte() - 48
  n = badd(n, bmul(v, mul))
  mul = bmul(mul, 10)
end
local mt = {}
for i = 1, #ms do
  mt[i] = ms:sub(i, i):byte() - 48
end
local pos = 1
local ret = 1
while true do
  if mt[#mt] % 2 == 1 then
    ret = bmul(ret, n)
  end
  for i = pos, #mt do
    if mt[i] % 2 == 1 then
      if i ~= #mt then
        mt[i + 1] = mt[i + 1] + 10
      end
    end
    mt[i] = mfl(mt[i] / 2)
  end
  if mt[pos] == 0 then
    pos = pos + 1
    if #mt < pos then break end
  end
  n = bmul(n, n)
end
print(ret)
0