結果
問題 |
No.1611 Minimum Multiple with Double Divisors
|
ユーザー |
👑 |
提出日時 | 2021-07-21 23:40:03 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,645 bytes |
コンパイル時間 | 118 ms |
コンパイル使用メモリ | 6,688 KB |
実行使用メモリ | 51,152 KB |
最終ジャッジ日時 | 2024-07-17 20:43:43 |
合計ジャッジ時間 | 7,230 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 2 |
other | TLE * 1 -- * 36 |
ソースコード
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 x = mfl(x / dv) local cnt = 1 while x % dv == 0 do x = mfl(x / dv) cnt = cnt + 1 end table.insert(tmp, {dv, cnt}) lim = mce(msq(x)) end if primepos == prime_num then break end primepos = primepos + 1 dv = primes[primepos] end if x ~= 1 then table.insert(tmp, {x, 1}) end return tmp end local primes = getprimes(mce(msq(50 * 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 dvp = getdivisorparts(x, primes) local tot = 1 for i = 1, #dvp do tot = tot * (1 + dvp[i][2]) end for j = 2, ans - 1 do local dvp2 = getdivisorparts(x * j, primes) local tot2 = 1 for i = 1, #dvp2 do tot2 = tot2 * (1 + dvp2[i][2]) end if tot * 2 == tot2 then ans = j break end end print(ans * x) end