結果
問題 | No.1730 GCD on Blackboard in yukicoder |
ユーザー | 👑 obakyan |
提出日時 | 2022-01-18 09:57:31 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,103 bytes |
コンパイル時間 | 118 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 43,904 KB |
最終ジャッジ日時 | 2024-11-23 13:17:57 |
合計ジャッジ時間 | 18,563 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 11 ms
16,128 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 11 ms
10,880 KB |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | TLE | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
ソースコード
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 function getdivisorCore(divisorparts, box) 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 - 1 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 box[ret] = box[ret] + 1 end end local function getdivisor(x, primes, box) local dvp = getdivisorparts(x, primes) getdivisorCore(dvp, box) end local n = io.read("*n") local box = {} for i = 1, 1000000 do box[i] = 0 end local primes = getprimes(1000) for i = 1, n do local a = io.read("*n") getdivisor(a, primes, box) end local ret = {} for i = 1, n do ret[i] = 0 end for i = 1, 1000000 do local cnt = box[i] if 0 < cnt then local rem = n - cnt ret[rem + 1] = i end end print(table.concat(ret, "\n"))