結果

問題 No.2119 一般化百五減算
ユーザー 👑 obakyanobakyan
提出日時 2022-11-05 18:14:03
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 49 ms / 2,000 ms
コード長 795 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 5,296 KB
実行使用メモリ 4,536 KB
最終ジャッジ日時 2023-09-26 16:22:31
合計ジャッジ時間 1,965 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

local n = io.read("*n")
local m = io.read("*n")
local t = {}
local lim = 100000
for i = 1, lim do
  t[i] = false
end
for i = 1, m do
  local a, b = io.read("*n", "*n")
  b = (b + a * 100010) % a
  if t[a] then
    if t[a] ~= b then
      print("NaN") os.exit()
    end
  else
    t[a] = b
  end
end
do
  local f = true
  for i = 1, lim do
    if t[i] and t[i] ~= 0 then
      f = false
      break
    end
  end
  if f then
    print(0) os.exit()
  end
end
local f = {}
for i = 1, n do
  f[i] = 0
end

local need = 0
for i = 1, lim do
  if t[i] then
    need = need + 1
    local b = t[i]
    local v = b
    if v == 0 then v = i end
    while v <= n do
      f[v] = f[v] + 1
      v = v + i
    end
  end
end
for i = 1, n do
  if f[i] == need then
    print(i) os.exit()
  end
end
print("NaN")
0