結果
問題 | No.1730 GCD on Blackboard in yukicoder |
ユーザー | 👑 obakyan |
提出日時 | 2022-01-18 09:58:27 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,179 bytes |
コンパイル時間 | 93 ms |
コンパイル使用メモリ | 5,248 KB |
実行使用メモリ | 31,104 KB |
最終ジャッジ日時 | 2024-11-23 13:18:16 |
合計ジャッジ時間 | 17,359 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 11 ms
31,104 KB |
testcase_02 | AC | 12 ms
10,880 KB |
testcase_03 | AC | 16 ms
10,880 KB |
testcase_04 | AC | 21 ms
10,880 KB |
testcase_05 | AC | 15 ms
10,880 KB |
testcase_06 | AC | 20 ms
10,880 KB |
testcase_07 | AC | 21 ms
10,880 KB |
testcase_08 | AC | 22 ms
10,880 KB |
testcase_09 | AC | 14 ms
10,880 KB |
testcase_10 | AC | 22 ms
11,136 KB |
testcase_11 | AC | 12 ms
10,880 KB |
testcase_12 | AC | 12 ms
10,752 KB |
testcase_13 | AC | 646 ms
23,552 KB |
testcase_14 | AC | 594 ms
23,552 KB |
testcase_15 | AC | 621 ms
23,552 KB |
testcase_16 | AC | 621 ms
23,552 KB |
testcase_17 | AC | 622 ms
23,808 KB |
testcase_18 | AC | 525 ms
23,936 KB |
testcase_19 | AC | 612 ms
23,680 KB |
testcase_20 | AC | 845 ms
23,680 KB |
testcase_21 | AC | 815 ms
23,680 KB |
testcase_22 | TLE | - |
testcase_23 | AC | 85 ms
22,144 KB |
testcase_24 | AC | 85 ms
22,272 KB |
testcase_25 | AC | 550 ms
28,800 KB |
ソースコード
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 for i = 2, n do ret[i] = ret[i] < ret[i - 1] and ret[i - 1] or ret[i] end print(table.concat(ret, "\n"))