結果

問題 No.251 大きな桁の復習問題(1)
ユーザー 👑 obakyanobakyan
提出日時 2020-05-04 22:06:34
言語 Lua
(LuaJit 2.1.1696795921)
結果
WA  
実行時間 -
コード長 799 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-07 06:31:20
合計ジャッジ時間 1,785 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

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
if n == 0 then
  print(0)
end
local m = 0
mul = 1
for i = #ms, 1, -1 do
  local v = ms:sub(i, i):byte() - 48
  m = (m + (v * mul) % (mod - 1)) % (mod - 1)
  mul = (mul * 10) % (mod - 1)
end
local ret = 1
while 0 < m do
  if m % 2 == 1 then
    ret = bmul(ret, n)
  end
  n = bmul(n, n)
  m = mfl(m / 2)
end
print(ret)
0