結果
| 問題 |
No.1611 Minimum Multiple with Double Divisors
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-08-04 15:24:51 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,509 bytes |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 6,944 KB |
| 実行使用メモリ | 7,168 KB |
| 最終ジャッジ日時 | 2024-08-04 15:25:22 |
| 合計ジャッジ時間 | 30,565 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 35 TLE * 2 |
ソースコード
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 ztime = 0
local primes = getprimes(mce(msq(100000000000)))
local q = io.read("*n")
for iq = 1, q do
local x = io.read("*n")
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
print(ans * x)
end
-- print(os.clock())
-- print(ztime)