結果
問題 | No.1611 Minimum Multiple with Double Divisors |
ユーザー | 👑 obakyan |
提出日時 | 2024-08-04 15:29:59 |
言語 | Lua (LuaJit 2.1.1696795921) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,624 bytes |
コンパイル時間 | 282 ms |
コンパイル使用メモリ | 7,068 KB |
実行使用メモリ | 10,580 KB |
最終ジャッジ日時 | 2024-08-04 15:30:29 |
合計ジャッジ時間 | 29,590 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 54 ms
7,040 KB |
testcase_01 | AC | 1,171 ms
9,964 KB |
testcase_02 | AC | 1,217 ms
10,276 KB |
testcase_03 | AC | 1,218 ms
10,272 KB |
testcase_04 | AC | 1,253 ms
9,948 KB |
testcase_05 | AC | 1,185 ms
10,308 KB |
testcase_06 | AC | 1,179 ms
10,116 KB |
testcase_07 | AC | 1,200 ms
10,084 KB |
testcase_08 | AC | 1,208 ms
10,312 KB |
testcase_09 | AC | 1,161 ms
10,112 KB |
testcase_10 | AC | 567 ms
7,040 KB |
testcase_11 | TLE | - |
testcase_12 | AC | 1,792 ms
10,276 KB |
testcase_13 | AC | 1,785 ms
10,580 KB |
testcase_14 | AC | 1,782 ms
10,124 KB |
testcase_15 | AC | 1,786 ms
10,308 KB |
testcase_16 | AC | 1,787 ms
10,192 KB |
testcase_17 | AC | 1,768 ms
10,124 KB |
testcase_18 | AC | 1,775 ms
10,332 KB |
testcase_19 | AC | 24 ms
7,168 KB |
testcase_20 | AC | 23 ms
7,040 KB |
testcase_21 | AC | 22 ms
7,040 KB |
testcase_22 | AC | 20 ms
7,040 KB |
testcase_23 | AC | 22 ms
7,040 KB |
testcase_24 | AC | 24 ms
7,168 KB |
testcase_25 | AC | 22 ms
7,040 KB |
testcase_26 | AC | 22 ms
7,040 KB |
testcase_27 | AC | 21 ms
7,040 KB |
testcase_28 | AC | 11 ms
7,040 KB |
testcase_29 | AC | 11 ms
7,040 KB |
testcase_30 | AC | 11 ms
7,168 KB |
testcase_31 | AC | 10 ms
7,040 KB |
testcase_32 | AC | 10 ms
7,168 KB |
testcase_33 | AC | 11 ms
7,040 KB |
testcase_34 | AC | 10 ms
7,168 KB |
testcase_35 | AC | 11 ms
7,040 KB |
testcase_36 | AC | 10 ms
7,040 KB |
testcase_37 | AC | 11 ms
7,040 KB |
testcase_38 | AC | 11 ms
7,168 KB |
ソースコード
local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs local bls, brs = bit.lshift, bit.rshift local Heapq = {} Heapq.create = function(self, lt) self.lt = lt self.cnt = 0 self.t = {} end Heapq.push = function(self, v) local hqlt = self.lt local hqt = self.t local c = self.cnt + 1 self.cnt = c hqt[c] = v while 1 < c do local p = brs(c, 1) if hqlt(hqt[c], hqt[p]) then hqt[c], hqt[p] = hqt[p], hqt[c] c = p else break end end end Heapq.pop = function(self) local hqlt = self.lt local hqt = self.t local ret = hqt[1] local c = self.cnt hqt[1] = hqt[c] c = c - 1 self.cnt = c local p = 1 while true do local d1, d2 = p * 2, p * 2 + 1 if c < d1 then break elseif c < d2 then if hqlt(hqt[d1], hqt[p]) then hqt[d1], hqt[p] = hqt[p], hqt[d1] end break else if hqlt(hqt[d1], hqt[d2]) then if hqlt(hqt[d1], hqt[p]) then hqt[d1], hqt[p] = hqt[p], hqt[d1] p = d1 else break end else if hqlt(hqt[d2], hqt[p]) then hqt[d2], hqt[p] = hqt[p], hqt[d2] p = d2 else break end end end end return ret end Heapq.new = function(lt) local obj = {} setmetatable(obj, {__index = Heapq}) obj:create(lt) return obj end 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 lim = mce(msq(x)) local primepos = 1 local dv = primes[primepos] local keys = {} local vals = {} while dv and dv <= lim do if x % dv == 0 then local cnt = 0 while x % dv == 0 do x = mfl(x / dv) cnt = cnt + 1 end table.insert(keys, dv) table.insert(vals, cnt) lim = mce(msq(x)) end primepos = primepos + 1 dv = primes[primepos] end if x ~= 1 then table.insert(keys, x) table.insert(vals, 1) end return keys, vals end local anstbl = {} local ztime = 0 local primes = getprimes(mce(msq(100000000000))) local q = io.read("*n") local function solve(x) local v = false for i = 1, #primes do local p = primes[i] if x % p ~= 0 then v = p break end end local ans = 1 * v local z1 = os.clock() local keys, vals = getdivisorparts(x, primes) ztime = ztime + os.clock() - z1 local tot = 1 for i = 1, #vals do tot = tot * (1 + vals[i]) end local insed = {} local hq = Heapq.new(function(a, b) return a < b end) for i = 1, #keys do hq:push(keys[i]) insed[keys[i]] = true end while 0 < hq.cnt do local top = hq:pop() if ans < top then break end local top_ = top local tot2 = tot for i = 1, #keys do local k = keys[i] local v = 0 while top % k == 0 do top = mfl(top / k) v = v + 1 end tot2 = mfl(tot2 * (vals[i] + v + 1) / (vals[i] + 1)) end if tot * 2 == tot2 then ans = top_ break end for i = 1, #keys do local nxt = top_ * keys[i] if not insed[nxt] then insed[nxt] = true hq:push(nxt) end end end return ans end for iq = 1, q do local x = io.read("*n") if not anstbl[x] then anstbl[x] = solve(x) end print(x * anstbl[x]) end -- print(os.clock()) -- print(ztime)