結果
問題 | No.1611 Minimum Multiple with Double Divisors |
ユーザー |
👑 |
提出日時 | 2024-08-04 15:29:59 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
TLE
|
実行時間 | - |
コード長 | 3,624 bytes |
コンパイル時間 | 282 ms |
コンパイル使用メモリ | 7,068 KB |
実行使用メモリ | 10,580 KB |
最終ジャッジ日時 | 2024-08-04 15:30:29 |
合計ジャッジ時間 | 29,590 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 36 TLE * 1 |
ソースコード
local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abslocal bls, brs = bit.lshift, bit.rshiftlocal Heapq = {}Heapq.create = function(self, lt)self.lt = ltself.cnt = 0self.t = {}endHeapq.push = function(self, v)local hqlt = self.ltlocal hqt = self.tlocal c = self.cnt + 1self.cnt = chqt[c] = vwhile 1 < c dolocal p = brs(c, 1)if hqlt(hqt[c], hqt[p]) thenhqt[c], hqt[p] = hqt[p], hqt[c]c = pelsebreakendendendHeapq.pop = function(self)local hqlt = self.ltlocal hqt = self.tlocal ret = hqt[1]local c = self.cnthqt[1] = hqt[c]c = c - 1self.cnt = clocal p = 1while true dolocal d1, d2 = p * 2, p * 2 + 1if c < d1 then breakelseif c < d2 thenif hqlt(hqt[d1], hqt[p]) thenhqt[d1], hqt[p] = hqt[p], hqt[d1]endbreakelseif hqlt(hqt[d1], hqt[d2]) thenif hqlt(hqt[d1], hqt[p]) thenhqt[d1], hqt[p] = hqt[p], hqt[d1]p = d1else breakendelseif hqlt(hqt[d2], hqt[p]) thenhqt[d2], hqt[p] = hqt[p], hqt[d2]p = d2else breakendendendendreturn retendHeapq.new = function(lt)local obj = {}setmetatable(obj, {__index = Heapq})obj:create(lt)return objendlocal 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 lim = mce(msq(x))local primepos = 1local dv = primes[primepos]local keys = {}local vals = {}while dv and dv <= lim doif x % dv == 0 thenlocal cnt = 0while x % dv == 0 dox = mfl(x / dv)cnt = cnt + 1endtable.insert(keys, dv)table.insert(vals, cnt)lim = mce(msq(x))endprimepos = primepos + 1dv = primes[primepos]endif x ~= 1 thentable.insert(keys, x)table.insert(vals, 1)endreturn keys, valsendlocal anstbl = {}local ztime = 0local primes = getprimes(mce(msq(100000000000)))local q = io.read("*n")local function solve(x)local v = falsefor i = 1, #primes dolocal p = primes[i]if x % p ~= 0 thenv = pbreakendendlocal ans = 1 * vlocal z1 = os.clock()local keys, vals = getdivisorparts(x, primes)ztime = ztime + os.clock() - z1local tot = 1for i = 1, #vals dotot = tot * (1 + vals[i])endlocal insed = {}local hq = Heapq.new(function(a, b) return a < b end)for i = 1, #keys dohq:push(keys[i])insed[keys[i]] = trueendwhile 0 < hq.cnt dolocal top = hq:pop()if ans < top then break endlocal top_ = toplocal tot2 = totfor i = 1, #keys dolocal k = keys[i]local v = 0while top % k == 0 dotop = mfl(top / k)v = v + 1endtot2 = mfl(tot2 * (vals[i] + v + 1) / (vals[i] + 1))endif tot * 2 == tot2 thenans = top_breakendfor i = 1, #keys dolocal nxt = top_ * keys[i]if not insed[nxt] theninsed[nxt] = truehq:push(nxt)endendendreturn ansendfor iq = 1, q dolocal x = io.read("*n")if not anstbl[x] thenanstbl[x] = solve(x)endprint(x * anstbl[x])end-- print(os.clock())-- print(ztime)