結果
問題 | No.2324 Two Countries within UEC |
ユーザー |
👑 |
提出日時 | 2023-05-28 19:11:28 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 357 ms / 2,000 ms |
コード長 | 1,237 bytes |
コンパイル時間 | 240 ms |
コンパイル使用メモリ | 6,944 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-26 23:32:31 |
合計ジャッジ時間 | 7,295 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 41 |
ソースコード
local mfl, mce = math.floor, math.ceil local mod = 1 local function bmul(x, y) local x1, y1 = x % 10000, y % 10000 local x2, y2 = mfl(x / 10000) % 10000, mfl(y / 10000) % 10000 local x3, y3 = mfl(x / 100000000), mfl(y / 100000000) local ret = (x1 * y1 + (x1 * y2 + x2 * y1) * 10000) % mod ret = (ret + (x1 * y3 + x2 * y2 + x3 * y1) * 10000 % mod * 10000 % mod) % mod ret = (ret + (x2 * y3 + x3 * y2) * 10000 % mod * 10000 % mod * 10000) % mod ret = (ret + x3 * y3 * 10000 % mod * 10000 % mod * 10000 % mod * 10000) % mod return ret end local function modpow(src, pow) local res = 1 while 0 < pow do if pow % 2 == 1 then res = bmul(res, src) pow = pow - 1 end src = bmul(src, src) pow = mfl(pow / 2) end return res end local function modinv(src) return modpow(src, mod - 2) end local n, m, p, q = io.read("*n", "*n", "*n", "*n") mod = p local a = mfl(m / p) local rem = m - p * a for iq = 1, q do local x, f = io.read("*n", "*n") x = x % mod if x == 0 then if f == 0 then print(m) else print(0) end else local v = bmul(f, modinv(x)) if v == 0 then v = p end if v <= rem then print(a + 1) else print(a) end end end