結果
問題 | No.1665 quotient replace |
ユーザー |
👑 |
提出日時 | 2022-01-09 00:14:45 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,135 bytes |
コンパイル時間 | 174 ms |
コンパイル使用メモリ | 6,820 KB |
実行使用メモリ | 21,312 KB |
最終ジャッジ日時 | 2024-11-14 09:59:51 |
合計ジャッジ時間 | 127,422 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 TLE * 1 |
ソースコード
local bxor = bit.bxorlocal mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abslocal function getprimes(x)local primes = {}local allnums = {}for i = 1, x do allnums[i] = true endfor i = 2, x doif allnums[i] thentable.insert(primes, i)local lim = mfl(x / i)for j = 2, lim doallnums[j * i] = falseendendendreturn primesendlocal function getdivisorparts(x, primes)local prime_num = #primeslocal tmp = {}local lim = mce(msq(x))local primepos = 1local dv = primes[primepos]while primepos <= prime_num and dv <= lim doif x % dv == 0 thenlocal t = {}t.p = dvt.cnt = 1x = mfl(x / dv)while x % dv == 0 dox = mfl(x / dv)t.cnt = t.cnt + 1endtable.insert(tmp, t)lim = mce(msq(x))endif primepos == prime_num then break endprimepos = primepos + 1dv = primes[primepos]endif x ~= 1 thenlocal t = {}t.p, t.cnt = x, 1table.insert(tmp, t)endreturn tmpendlocal tt = {0}local function getdivisorCore(divisorparts)local m = {}local pat = 1local len = #divisorpartslocal allpat = 1for i = 1, len doallpat = allpat * (1 + divisorparts[i].cnt)endfor t_i_pat = 0, allpat - 2 dolocal div = allpatlocal i_pat = t_i_patlocal ret = 1for i = 1, len dodiv = mfl(div / (divisorparts[i].cnt + 1))local mul = mfl(i_pat / div)i_pat = i_pat % divfor j = 1, mul doret = ret * divisorparts[i].pendendm[tt[ret]] = trueendfor i = 0, 1000000 doif not m[i] then return i endendassert(false)return falseendlocal function getdivisor(x, primes)local dvp = getdivisorparts(x, primes)return getdivisorCore(dvp)endlocal primes = getprimes(1000)for i = 2, 1000 * 1000 dott[i] = getdivisor(i, primes)end-- print(os.clock())-- os.exit()local n = io.read("*n")local ret = 0for i = 1, n dolocal a = io.read("*n")ret = bxor(ret, tt[a])endprint(ret == 0 and "black" or "white")