結果

問題 No.1680 Sum and Difference
ユーザー 👑 obakyanobakyan
提出日時 2022-04-30 21:01:08
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 997 bytes
コンパイル時間 242 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-12 12:56:37
合計ジャッジ時間 1,078 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local mod = 1000000007LL
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 a, b = io.read():match("(%d+) (%d+)")
a = lltonumber(a)
b = lltonumber(b)
local ans = false
if a == 0LL then
  ans = (b / 2LL) * 2LL + 1LL
elseif b == 0LL then
  ans = (a / 2LL) * 2LL + 1LL
elseif (a + b) % 2LL == 0LL then
  local x1 = (a - b) / 2LL
  local x2 = (-a - b) / 2LL
  local x3 = (a + b) / 2LL
  local width = x1 - x2 + 1LL
  local height = x3 - x1 + 1LL
  local p = ((width + mod - 1LL) % mod) * ((height + mod - 1LL) % mod)
  p = p % mod
  local q = (width % mod) * (height % mod)
  q = q % mod
  ans = (p + q) % mod
else
  local l1 = a + 1LL
  local l2 = b + 1LL
  local rm = (a % mod) * (b % mod) + ((a + 1LL) % mod) * ((b + 1LL) % mod)
  rm = rm % mod
  local add = ((a * 2LL + 1LL) % mod) * ((b * 2LL + 1LL) % mod)
  ans = (add + mod - rm) % mod
end

ans = tostring(ans % mod):gsub("LL", "")
print(ans)
0