結果
問題 |
No.1680 Sum and Difference
|
ユーザー |
👑 |
提出日時 | 2022-04-30 21:01:08 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 2 ms / 1,000 ms |
コード長 | 997 bytes |
コンパイル時間 | 388 ms |
コンパイル使用メモリ | 5,632 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-30 01:18:15 |
合計ジャッジ時間 | 1,127 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
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)