結果

問題 No.1665 quotient replace
ユーザー 👑 obakyanobakyan
提出日時 2022-01-09 00:16:24
言語 Lua
(LuaJit 2.1.1696795921)
結果
TLE  
実行時間 -
コード長 2,171 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 6,944 KB
実行使用メモリ 45,792 KB
最終ジャッジ日時 2024-04-26 19:38:28
合計ジャッジ時間 131,845 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,691 ms
21,164 KB
testcase_01 AC 2,553 ms
20,864 KB
testcase_02 AC 2,702 ms
21,048 KB
testcase_03 AC 2,511 ms
20,932 KB
testcase_04 AC 2,713 ms
21,000 KB
testcase_05 AC 2,750 ms
21,004 KB
testcase_06 AC 2,690 ms
21,000 KB
testcase_07 AC 2,715 ms
21,148 KB
testcase_08 AC 2,753 ms
21,020 KB
testcase_09 AC 2,667 ms
21,892 KB
testcase_10 AC 2,838 ms
31,808 KB
testcase_11 TLE -
testcase_12 AC 2,719 ms
23,784 KB
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 AC 2,646 ms
21,260 KB
testcase_19 AC 2,685 ms
20,892 KB
testcase_20 AC 2,784 ms
21,028 KB
testcase_21 AC 2,693 ms
21,024 KB
testcase_22 AC 2,662 ms
21,148 KB
testcase_23 AC 2,726 ms
21,172 KB
testcase_24 AC 2,790 ms
21,112 KB
testcase_25 AC 2,747 ms
21,128 KB
testcase_26 AC 2,721 ms
21,156 KB
testcase_27 AC 2,938 ms
21,132 KB
testcase_28 AC 2,737 ms
21,584 KB
testcase_29 AC 2,675 ms
22,908 KB
testcase_30 AC 2,907 ms
27,996 KB
testcase_31 AC 2,980 ms
32,984 KB
testcase_32 TLE -
testcase_33 AC 2,958 ms
27,172 KB
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 AC 2,979 ms
34,448 KB
testcase_38 TLE -
testcase_39 AC 2,905 ms
32,420 KB
testcase_40 TLE -
testcase_41 TLE -
testcase_42 AC 2,764 ms
21,236 KB
testcase_43 AC 2,690 ms
21,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local bxor = bit.bxor
local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs

local function getprimes(x)
  local primes = {}
  local allnums = {}
  for i = 1, x do allnums[i] = true end
  for i = 2, x do
    if allnums[i] then
      table.insert(primes, i)
      local lim = mfl(x / i)
      for j = 2, lim do
        allnums[j * i] = false
      end
    end
  end
  return primes
end

local function getdivisorparts(x, primes)
  local prime_num = #primes
  local tmp = {}
  local lim = mce(msq(x))
  local primepos = 1
  local dv = primes[primepos]
  while primepos <= prime_num and dv <= lim do
    if x % dv == 0 then
      local t = {}
      t.p = dv
      t.cnt = 1
      x = mfl(x / dv)
      while x % dv == 0 do
        x = mfl(x / dv)
        t.cnt = t.cnt + 1
      end
      table.insert(tmp, t)
      lim = mce(msq(x))
    end
    if primepos == prime_num then break end
    primepos = primepos + 1
    dv = primes[primepos]
  end
  if x ~= 1 then
    local t = {}
    t.p, t.cnt = x, 1
    table.insert(tmp, t)
  end
  return tmp
end

local tt = {0}

local function getdivisorCore(divisorparts)
  local m = {}
  local pat = 1
  local len = #divisorparts
  local allpat = 1
  for i = 1, len do
    allpat = allpat * (1 + divisorparts[i].cnt)
  end
  for t_i_pat = 0, allpat - 2 do
    local div = allpat
    local i_pat = t_i_pat
    local ret = 1
    for i = 1, len do
      div = mfl(div / (divisorparts[i].cnt + 1))
      local mul = mfl(i_pat / div)
      i_pat = i_pat % div
      for j = 1, mul do
        ret = ret * divisorparts[i].p
      end
    end
    m[tt[ret]] = true
  end
  for i = 0, 1000000 do
    if not m[i] then return i end
  end
  assert(false)
  return false
end

local function getdivisor(x, primes)
  local dvp = getdivisorparts(x, primes)
  return getdivisorCore(dvp)
end


local primes = getprimes(1000)

for i = 2, 1000 * 1000 do
  tt[i] = getdivisor(i, primes)
end
-- print(os.clock())
-- os.exit()
local n = io.read("*n", "*l")
local ret = 0
local s = io.read()
for w in s:gmatch("%d+") do
  local a = tonumber(w)
  ret = bxor(ret, tt[a])
end
print(ret == 0 and "black" or "white")
0